input
Package: WA2L/edrc 1.5.57
Section: Library Commands (3)
Updated: 06 October 2021
Index
Return to Main Contents
NAME
input - prompt for an input
SYNOPSIS
edrc/lib/input
input
"prompt"
[
"default input"
[
options
]]
AVAILABILITY
WA2L/edrc
DESCRIPTION
This command is used in scripts to prompt a user for an input.
It is possible to verify the users input using a number of options.
As long as the input does not conform to the option specified the
input prompt is repeated.
It is also possible to specify a default value that takes in effect
when <ENTER> or <RETURN> without entering an input is pressed.
All input is logged to a logfile if the environment variable
$EDRC_LOGFILE
is set and the
NO_LOG
option isn't set.
OPTIONS
-
-
usage message
- "prompt"
-
prompt to be displayed.
- "default input"
-
default input. This input will be returned if the <ENTER> key is
pressed without entering anything on the input prompt.
- options
-
a list of comma separated options of the list below. The input
is verified against all options listed. Therefore be careful not to
provide an option list that makes it impossible to enter any data
(e.g.
ALPHA,DIGIT
).
-
- NOT_NULL
-
null input is not accepted.
- NO_LOG
-
do not record the input to the logfile.
- NO_TRIM
-
do not trim whitespaces from begin and end of input. Default is
to trim those whitespaces.
Hint: If the input is a whitespace and the option
NOT_NULL
is set, the input is not accepted.
- NO_ECHO
-
do not echo the input to stdout. This is useful if you query passwords.
- LOG_STARS
-
log stars (*****) to the logfile instead of the real input. This option
should be used always if you query passwords with the
input
command.
- TTY
-
read input from
tty
and write prompt to
tty.
- MINLEN=len
-
accept only input with a minimal length of
len.
- MAXLEN=len
-
accept only input up to a maximal length of
len.
- ALPHA
-
accept only inputs consisting of letters (a - Z).
- DIGIT
-
accept only numbers as unsigned integer values (0 - 9).
- FLOAT
-
accept only numbers as signed floating point values. Examples:
+.125, +0.125, 0.125, 3.1415, 815, -.125, -0.125, -3.1415, -815.
- ALNUM
-
accept only alphanumeric input (a - Z, 0 - 9).
- ALNUM+SPACE
-
accept only alphanumeric input including spaces (a - Z, 0 - 9, ' ').
- ALNUM+_
-
accept only alphanumeric and _ (a - Z, 0 - 9, _).
- IPV4
-
accept only IP version 4 addresses (0.0.0.0 - 255.255.255.255).
- HH:MM
-
accept only time values in the format HH:MM (00:00 - 24:00).
- HH:MM:SS
-
accept only time values in the format HH:MM:SS (00:00:00 - 24:00:00).
- HHH:MM
-
accept only time (hour:minutes) values in the format hour:MM (00:00 - 9999999:59)
in contrast to HH:MM, the hours are not limited to 24 hours.
- HHH:MM:SS
-
accept only time values in the format hour:MM:SS (00:00:00 - 9999999:59:59)
in contrast to HH:MM:SS, the hours are not limited to 24 hours.
- MM/DD
-
accept only dates (month and day) in the format MM/DD (01/01 - 12/31).
- MM/DD/YYYY
-
accept only dates in the format MM/DD/YYYY (01/01/0000 - 12/31/9999).
- DD.MM
-
accept only dates (day and month) in the format DD.MM (01.01 - 31.12).
- DD.MM.YYYY
-
accept only dates in the format DD.MM.YYYY (01.01.0000 - 31.12.9999).
- YYYY-MM-DD
-
accept only dates in the military format YYYY-MM-DD (0000-01-01 - 9999-12-31).
ENVIRONMENT
- $EDRC_LOGFILE
-
the accepted input read by
input
is logged to the file specified in this environment variable (if set).
EXIT STATUS
- 0
-
no error.
- 2
-
command aborted pressing Ctrl+C.
- 4
-
usage listed.
FILES
- /dev/tty
-
terminal device file when option
TTY
is used.
This device file is read if the resolution of the current pseudo device
of the terminal is not possible.
EXAMPLES
The following examples are script cut-outs of Bourne-, Korn- or
Bash shell scripts:
- 1) filename input
-
filename=`input "Package Filename" "" NOT_NULL,ALNUM+_`
- 2) input a number and log everything to a logfile
-
Logfile=/var/log/process_counts.log
EDRC_LOGFILE=$Logfile; export EDRC_LOGFILE
pause=40
ok=n
{
while [ ok != y ]; then
pause=`input "pause between process counts" $pause DIGIT`
ok=`choice "input OK? <yn>" yn n`
done
echo "press <Ctrl>+<C> to stop"
while [ 1 = 1 ]; do
echo "number of processes: `ps -ef | wc -l`"
sleep $pause
done
} >> $Logfile
- 3) prompt for a password input
-
Logfile=/var/log/passwordchange.log
EDRC_LOGFILE=$Logfile; export EDRC_LOGFILE
new=new
verify=verify
while [ "$new" != "$verify" ]; then
new=`input "New password" "" NOT_NULL,LOG_STARS,NO_ECHO`
verify=`input "Retype new password" "" NOT_NULL,LOG_STARS,NO_ECHO`
done
SEE ALSO
edrcintro(1),
choice(3),
input_targets(3),
sh(1),
ksh(1)
NOTES
-
BUGS
The dates 09/03/1752 - 09/13/1752 are accepted, despite
of the fact that those dates did never occur because it is assumed
that the Gregorian Reformation took place on the 09/03/1752.
AUTHOR
input was developed by Christian Walther. Send suggestions
and bug reports to wa2l@users.sourceforge.net .
COPYRIGHT
Copyright © 2013
Christian Walther
This is free software; see
edrc/doc/COPYING
for copying conditions. There is ABSOLUTELY NO WARRANTY; not
even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This document was created by man2html
using the manual pages.
Time: 16:53:14 GMT, August 28, 2024