I'm trying to write a script where I want to check if any of the parameters passed to a bash script match a string. The way I have it setup right now is
if [ "$3" != "-disCopperBld" -a "$4" != "-disCopperBld" -a "$5" != "-disCopperBld" -a "$6" != "-disCopperBld"]
but there might be a large number of parameters, so I was wondering if there is a better way to do this?
I tried this chunk of code out, and called the script with the option, -disableVenusBld, but it still prints out "Starting build". Am I doing something wrong? Thanks in advance!
while [ $# -ne 0 ] do arg="$1" case "$arg" in -disableVenusBld) disableVenusBld=true ;; -disableCopperBld) disableCopperBld=true ;; -disableTest) disableTest=true ;; -disableUpdate) disableUpdate=true ;; *) nothing="true" ;; esac shift done if [ "$disableVenusBld" != true ]; then echo "Starting build" fi
It looks like you're doing option handling in a shell script. Here's the idiom for that:
(There are a couple of conventions for indenting the
;;, and some shells allow you to give the options as
(--opt1), to help with brace matching, but this is the basic idea)