Taking user input
read user input as a variable.
will save what the user entered and save it as a variable called
You can ask a question first, like so:
echo "What's your name?" read input echo "Your name is: $input"
By default, it’ll ask for input on a new line. You can supress the new line with
You can use
read instead of
$1. So instead of
foo.sh Aamnah echo "Your name is $1"
where you are passing my name as an argument, you can prompt me for it, like so:
foo.sh echo -n "What's your name?" read name echo "Your name is $name"