Most Linux commands accept options and arguments. There are multiple ways of doing this in bash, but in this video, focus on the getopts command to process command options and options with arguments, and then reset the positional arguments so $1 is still the first argument after options.
- [Instructor] The last way that we will input…information into our scripts…and make them act more like Linux system commands,…is by allowing command line options.…For instance, with the ls command,…we can type in ls, space, dash, l,…and the dash l option modifies the ls command output.…Be sure that you're in your tilde slash bin directory.…Type in clear,…and now create a script called getopts dot sh,…by typing in vi, space, getopts dot sh,…and hit Enter.…Go into insert mode and add…hash, bang, slash, bin, slash, bash.…New line, while, space, getopts, space,…double quote, colon, a, double quote, space,…opt, semi colon, space, do.…
New line, case, space, dollar sign, opt, space, in.…New line, a, right parentheses, space, echo, space,…double quote, you passed the dash a option, double quote,…space, greater than, and press and, two,…space, semi colon, semi colon.…New line, backslash, question mark, right parentheses,…echo, space, double quote, invalid, space option, colon,…space, dash, dollar sign, opt, double quote,…
Note: This course also helps you study to pass the Red Hat Certified Engineer (RHCE) exam—the benchmark certification for Red Hat Enterprise Linux.
- Basics of bash scripting
- Bash debugging
- Loading files in scripts
- Prompting for input
- Piping data into a script
- Outputting data from a script
- Controlling the flow of bash scripts with conditions
- Looping bash scripts
- Reviewing real-world examples