Shell Scripting getopts options

The getopts options are used in shell scripts to parse arguments passed to them. When arguments are passed on the command line, getopts parse those arguments instead of command lines.

Options are written starting with a hyphen (-), followed by the letter. For example, -a, -b, -c, -d, etc.

Example 1 without argument:

Linux Shell Scripting Get script options with getopts 1

Look at the above snapshot, we have created three options -a, -b and-c. And no arguments are required for any option.

Linux Shell Scripting Get script options with getopts 2

Look at the above snapshot, this is the sample output from the above script.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *