Arunachalam
Arunachalam

Reputation: 6037

how to Enter data from keyboard in shell programming

how to Enter data from keyboard in shell programming ?

some command similar to scanf in c

Upvotes: 11

Views: 29589

Answers (2)

rashedcs
rashedcs

Reputation: 3725

You may use "cat"

Input can be accomplished using the cat statement.

    #!/bin/sh
    name=$(cat)
    echo "Welcome" "$name"

If we take input as Bash. Then the output :

Welcome Bash

Upvotes: 0

Pascal MARTIN
Pascal MARTIN

Reputation: 401022

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

Upvotes: 26

Related Questions