Join Scott Simpson for an in-depth discussion in this video Working with flags, part of Up and Running with Bash Scripting.
…If you've been working with the batch command line…environment for awhile, you're bound to have come across flags.…They're specific options that you can use to pass information…into a program, and they usually start with a dash.…You can make use of these in your batch script by way of the get opt function.…Let's say you wanted to make a script that accepts a username and password.…I could certainly use arguments for this, but then I'd need to…make sure that the username and password were entered in a certain order.…Let's take a look at how to set this up with a while loop, using…the get-opts function, I'll specify an up…string, which defines what flags I'm looking for.…
Here I'll use U:P:, which means I'm looking for a dash U and a dash P.…So I'm using the case statement using option as a…variable and when that option matches u, it sets user…equal to OPTARG, which is the value that's passed in…from the user following dash u at the command line.…The same thing happens for dash p.…So let's take a look at this running.…
- 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.