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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pattern matching in shell script 2

Status
Not open for further replies.

fireant

Technical User
Aug 12, 2001
28
0
0
PH
Hi,

is this the correct and most concise syntax to match an argument to just two items?

if [ "$1" == "-[dD]" ]; then

ACTION
fi


I want a more concise version to the one below that's why i'm asking.

if [ "$1" == "-d" -o "$1" == "-D" ]; then

ACTION
fi


TIA,

Louie C.
 
Louie -

If you're not familiar with it, you may want to check out getopts...

man bash or ksh and then search for getopts


Biker
Systems/Network Administrator
LiveFire Labs - Hands-On Technical e-Learning
 
case is the facility you want, getopts, as previously
mentioned is the way to handle complex options given to
a script via args but generally getopts uses the case
construct for interpreting and command logic.
 
Thanks to both of you guys and sorry for the late reply.

I'm gonna look at this getopts builtin and let you know if I'm successful.

Thanks again for pointing me in the right direction! Louie C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top