tags:

views:

135

answers:

1

how to Enter data from keyboard in shell programming ?

some command similar to scanf in c

+6  A: 

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
Pascal MARTIN
Bash: "read" has some useful options, e.g. -p to specify a prompt:read -p 'enter a value : ' my_varPlease see "help read" for more.
fgm