Correct to check for a command line flag in bash

Posted by BCS on Stack Overflow See other posts from Stack Overflow or by BCS
Published on 2010-05-20T15:45:56Z Indexed on 2010/05/20 16:00 UTC
Read the original article Hit count: 155

Filed under:
|
|

In the middle of a scrip, I want to check if a given flag was passed on the command line. The following does what I want but seems ugly:

if echo $* | grep -e "--flag" -q
then
  echo ">>>> Running with flag"
else
  echo ">>>> Running without flag"
fi

Is there a better way?

Note: I explicitly don't want to list all the flags in a switch/getopt. (And BTW the bodies of the if just set a set of vars)

© Stack Overflow or respective owner

Related posts about bash

Related posts about command-line