Join Scott Simpson for an in-depth discussion in this video Getting input during execution, part of Up and Running with Bash Scripting.
- View Offline
- Exercise Files
…So, you just saw how to get user input at the command line, but sometimes it's…not practical to have all of the values…you're looking for specified when you run the script.…Luckily, there's a way to get input during the execution of a script.…I'll write a typical question and then write read name.…The read keyword pauses the script to wait for input.…Followed by return or enter, and it stores that input in the variable you specify.…Here, I've used name.…There are also some options that read can accept.…Let's ask for a password, and here I'll use read -s followed by a variable name.…
The -s means silent, which means that it won't show the characters that I type in.…I can also write everything on one line with a…-p option, which writes out a prompt before the input area.…And let's echo all that out just to see what's going on.…And if I run this, first I'm prompted for my name.…And then my password, which you can see is…not appearing when I type, and then our inline prompt.…What's your favorite animal?…I like cats.…
- What is Bash?
- Managing output with grep, awk, and cut
- Understanding Bash script syntax
- Creating a basic Bash script
- Displaying text with "echo"
- Working with numbers, strings, and arrays
- Reading and writing text files
- Working with loops
- Using functions
- Getting user input during execution
- Ensuring a response
Skill Level Beginner
1. Working with the Command Line
2. Building Bash Scripts
3. Control Structures
4. Interacting with the User
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.