getopts command

This command is used to check valid command line argument are passed to script. Usually used in while loop.Syntax: getopts {optsring} {variable1}

getopts is used by shell to parse command line argument. As defined in man pages: "optstring contains the option letters to be recognized; if a letter is followed by a colon, the option is expected to have an argument, which should be separated from it by white space. Each time it is invoked, getopts places the next option in the shell variable variable1, When an option requires an argument, getopts places that argument into the variable OPTARG. On errors getopts diagnostic messages are printed when illegal options or missing option arguments are encountered. If an illegal option is seen, getopts places ? into variable1." Examlpe: We have script called ani which has syntax as ani -n -a -s -w -d Options: These are optional argument -n name of animal -a age of animal -s sex of animal -w weight of animal -d demo values (if any of the above options are used their values are not taken)