Notes

Taking user input

Edit on GitHub


Bash Scripting

You can read user input as a variable.

For example:

1read name

will save what the user entered and save it as a variable called name.

You can ask a question first, like so:

1echo "What's your name?"
2read input
3echo "Your name is: $input"

By default, it’ll ask for input on a new line. You can supress the new line with -n

You can use read instead of $1. So instead of

1foo.sh Aamnah
2echo "Your name is $1"

where you are passing my name as an argument, you can prompt me for it, like so:

1foo.sh
2echo -n "What's your name?"
3read name
4echo "Your name is $name"