Linux - How do you take a single line of input from the user in a shell script?
One line is read from the standard input (keyboard), or from file descriptor FD if the -u option is supplied, and the first word is assigned to the first NAME, the second word to the second NAME, and so on, with leftover words assigned to the last NAME.
Syntax:
read {variable-name}
read -p {’Prompt text’} {variable-name}
Read single line of input from the user and store to variable called dbname:
read dbname
OR
read -p 'Enter Database name : ' dbname
To display variable value, enter:
echo $dbname
Sample shell script
Comments
Post a Comment