What is the easiest (and possibly one-liner) way to check for the absence of a specific argument in a bash script, disregarding the argument order ?
I would like to assign at the beginning of the script a "boolean" variable named REAL_RUN
with true
or false
based on the absence or presence of an argument --dry-run
included among all the script arguments. Something like this:
REAL_RUN=... # <-- what to put here ?
if [ "$REAL_RUN" = true ] ; then
# do something
fi
I expect REAL_RUN
to be assigned true
with the following cases:
./run.sh
./run.sh foo bar
./run.sh foo --dry-run-with-unexpected-suffix bar
./run.sh foo ------dry-run bar
Instead, with the following examples REAL_RUN
must be set to false
./run.sh --dry-run
./run.sh foo --dry-run
./run.sh --dry-run bar
./run.sh foo --dry-run bar