Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Enter data from keyboard in shell programming

Tags:

bash

shell

unix

how to Enter data from keyboard in shell programming ?

some command similar to scanf in c

like image 321
Arunachalam Avatar asked Dec 10 '09 05:12

Arunachalam


People also ask

How do you enter data into shell?

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.

How do you read keyboard input in shell script?

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.

Which command receives data input from the user's keyboard?

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.


1 Answers

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
like image 117
Pascal MARTIN Avatar answered Nov 02 '22 03:11

Pascal MARTIN