how to Enter data from keyboard in shell programming ?
some command similar to scanf in c
Bash: "read" has some useful options, e.g. -p to specify a prompt: read -p 'enter a value : ' my_var Please see "help read" for more. -s option behaves great for password entries that we don't wish to be displayed: The -s option causes input coming from a terminal to not be echoed.
In this topic, we will learn how to read the user input from the terminal and the script. To read the Bash user input, we use the built-in Bash command called read. It takes input from the user and assigns it to the variable. It reads only a single line from the Bash shell.
The input() function gets user input (keyboard) and stores it into variable name. Here name is a variable. The print() function shows it to the screen. The user must press the enter key in the command line.
You can use "read
" :
$ cat ./test.sh
#!/bin/sh
echo -n "enter the value : "
read my_var
echo "The value is : $my_var"
And, executing the script :
$ sh ./test.sh
enter the value : 145
The value is : 145
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With