O'Reilly logo

Linux Shells by Example by Ellie Quigley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.10. Processing Command Line Options with getopts

If you are writing scripts that require a number of command line options, positional parameters are not always the most efficient. For example, the Linux lscommand takes a number of command line options and arguments. (An option requires a leading dash; an argument does not. ) Options can be passed to the program in several ways: ls -laFi, ls -i -a -l -F, ls -ia -F, and so forth. If you have a script that requires arguments, positional parameters might be used to process the arguments individually, such as ls -l -i -F . Each dash option would be stored in $1, $2, and $3, respectively. But, what if the user listed all of the options as one dash option, as in ls -liF? Now the -liF would all be ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required