Results 1 to 3 of 3
Hi. Im wondering if there is a way to use flags when starting a script.
Something like this.
Code:
Script -a -b 10
Right now Ive got something like this.
...
- 10-13-2009 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 9
BASH: Script Input Flags
Hi. Im wondering if there is a way to use flags when starting a script.
Something like this.
Right now Ive got something like this.Code:Script -a -b 10
So with that code I can only use flags ( -a -b ). Can I do the -b 10 so it will store say varB=10?Code:while getopts ab AA do case $AA in a) var="value" ;; esac done
- 10-13-2009 #2Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,695
Getopts command in Linux Shell Script
From the manual page,
"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 variable_name, 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 variable_name."
- 10-13-2009 #3Just Joined!
- Join Date
- Oct 2009
- Posts
- 9
So then the script would look like this.
when I run the scirpt like thisCode:while getopts ab: AA do case $AA in a) var="value" ;; b) varB=$optarg esac done
So $varB = 10?Code:Script -a -b 10


Reply With Quote