BASH scripts check for arguments
I know that $1 ... $n will set the argument to the values but what happened if I have many options in one scripts lets suppose.
I can run: myscript -1stargument -2ndargument -3rdargument or myscript -1stargument or myscript -1stargument -3rdargument . . . In my scripts I have if [ $1 = "-1stargument" -o $2 = "-2ndargument"] #for every isntruction i need fi but is there any wayu to do: if [ (any arguments or commands) = "(mydesired option ] ; then (do this...) fi ? Thanks |
Code:
for argument in $@ ;do |
getopts is designed for option parsing. It's one of those things that is better learned by example than by reading the documentation. Here's my getopts template.
EDIT: corrected ANSI string usage (in red). Code:
# Set defaults that may be overriden by command line parsing |
Quote:
Code:
for argument in "$@"; do |
Thank you to catkin for that post; I had thought about doing something similar, but it was one of many things that I never got around to.
If you want a tutorial, you could read here. |
Quote:
|
Thanks! I will give it a try on Monday!
|
All times are GMT -5. The time now is 04:30 PM. |