Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script Input Flags

Status
Not open for further replies.

Grizzly521

Technical User
Oct 12, 2009
7
US
Hi. Im wondering if there is a way to use flags when starting a script.
Something like this.

Script -a -b 10

Right now Ive got something like this.


while getopts ab AA
do case $AA in
a) var="value"
;;
esac
done


So with that code I can only use flags ( -a -b ). Can I do the -b 10 so it will store say varB=10?
 
See the man page for your shell for details (as getopts is usually a shell built-in), but briefly, if you follow an option with a colon in the getopts string, it will set $OPTARG to the value of the next parameter on the command-line.

Code:
while getopts a:b: AA
   do case $AA in
       a) var="$OPTARG"
       ;;
   esac
done

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top