Join Scott Simpson for an in-depth discussion in this video Ensuring a response, part of Up and Running with Bash Scripting.
- View Offline
- Exercise Files
…While it's great to ask for input, you probably…want to build some error tolerance into your script.…What happens if someone skips a prompt by just pressing Enter?…There's a few ways to deal with this pretty easily.…First, let's take a look a case where…we have a script that requires arguments to run.…So this script checks for the number of arguments.…And because it wants to have three, it won't run the program if it doesn't.…Instead, it returns a usage recommendation.…Instead of just exiting or failing somewhere along the road…when it comes time to use an argument that wasn't provided.…I'll save this, Exit,…and run the script.…
Since I haven't provided any arguments, I get the usage recommendation.…If I provide just a few arguments, the condition of having three…arguments is still not satisfied, so I get the usage recommendation again.…But if I give it three arguments, which…is what it's looking for, then the program executes.…Alternatively, we could set up a loop to not allow…the user to continue without specifying some kind of input.…
- 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.