From the course: Learning Bash Scripting

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Getting input during execution

Getting input during execution - Bash Tutorial

From the course: Learning Bash Scripting

Getting input during execution

- [Narrator] In a script, we'll often need to ask for input interactively. Sometimes it's not practical to expect a user to provide all the information a script needs through arguments or options. Or the script may not always need the same information and will need to follow a process the user selects and ask for information accordingly. To do this, we can use the read keyword. We saw a read earlier used to read lines from a file. But if we don't provide a file to read from, the read command pauses the execution of the script, until the user provides a text string in response, and assigns that response to a variable we can use in the script. I'll open up my script here and ask for a name. I'll write echo, what is your name? Then I'll write, read name. This will display a text prompt and then wait for the user to respond and press enter, at which time the user's response will be stored in the variable name. There's also…

Contents