Reputation: 7234
Let say I have this line in a shell script in unix:
read -n 1
It will prompt the user to get value but is there a way to call the script so it takes the input as argument instead?
Like this for example:
myscript.sh "M"
I want to call the script from a build engine so it cannot answer with keyboard input.
Upvotes: 0
Views: 1266
Reputation: 1081
To use argument values in shell script you can pass the argument with the script and then refer them using $1, $2, $3 and so on.
Upvotes: 2
Reputation: 784898
You can use Here Strings
in bash
:
myscript.sh <<< "M"
Or use pipeline:
echo "M" | myscript.sh
Upvotes: 1
Reputation: 3776
Use this with some frequency:
hello() { read -n1 CHAR; echo $CHAR; } echo world | hello
Upvotes: 0