…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.…
Author
Released
11/26/2013- 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
Duration
Views
Related Courses
-
Linux: Bash Shell and Scripts
with Kevin Dankwardt2h 46m Intermediate -
Unix for Mac OS X Users
with Kevin Skoglund6h 35m Beginner
-
Introduction
-
Welcome1m 1s
-
-
1. Working with the Command Line
-
What's Bash?2m 27s
-
Tilde and brace expansion3m 49s
-
Creating a basic Bash script1m 52s
-
-
2. Building Bash Scripts
-
Displaying text with echo1m 32s
-
Working with variables2m 32s
-
Command substitution1m 9s
-
Working with numbers2m 21s
-
Comparing values3m 13s
-
Working with strings3m 9s
-
Coloring and styling text6m 15s
-
Working with arrays2m 35s
-
Using here documents1m 43s
-
-
3. Control Structures
-
Introducing for loops3m 13s
-
Using functions2m 25s
-
4. Interacting with the User
-
Working with arguments1m 51s
-
Working with flags2m 18s
-
Ensuring a response3m 15s
-
-
Conclusion
-
Next steps48s
-
- 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.
CancelTake 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.
Share this video
Embed this video
Video: Getting input during execution