3
I need to check for user provided options in my bash script, but the options won't always be provided while calling the script. For example the possible options can be -dontbuild -donttest -dontupdate in any combination, is there a way I could check for them? Sorry if this question is real basic, I'm new to bash scripting.
Thanks
EDIT: 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
What purpose does doing it this way serve? It's functionally identical to the answer I gave but has an unnecessary conditional, variable assignment and
shift
adding extra weight. – Paused until further notice. – 2010-09-08T20:57:09.4231Dennis, you actually don't iterate through the arguments.
for arg
doesn't actually work in bash, you need to reference $1, $2, etc. You need the shift to actually iterate through the arguments, and the extra var ARG is to be able to use shift right away, so any params are in $1 – Rich Homolka – 2010-09-08T21:13:56.5371
for arg
does an implicit iteration over$@
so it most certainly does work. Try it. You could also do it explicitly withfor $arg in $@
. By not usingshift
you can leave$@
intact. – Paused until further notice. – 2010-09-09T01:25:36.853