The syntax would be like this:
Code:
if [ "$1" != "-i" ] || [ "$1" != "-I" ]
If you're parsing command line options, you might want to take a look at the bash internal
getopt (edit: and
getopts) which can be used to validate options for you.
For example, if you have a script which can take the options -a -b and -C, where -b takes an argument to the option, you might do it like this:
Code:
#!/bin/bash
while getopts "ab:C" option; do
case $option in
a|C)
echo "we have option: $option (no argument for this option)"
;;
b)
echo "we have option: $option with argument: $OPTARG"
;;
*)
echo "ERROR - unknown option" >&2
exit 1
;;
esac
done
# remove options from parameter list, leaving just remaining parameters
shift $(($OPTIND - 1))
for p in "$@"; do
echo "post-option parameter: $p"
done
An example invocation and output:
Code:
% ./test.sh -a -b "my option argument" -C now the rest of the parameters
we have option: a (no argument for this option)
we have option: b with argument: my option argument
we have option: C (no argument for this option)
post-option parameter: now
post-option parameter: the
post-option parameter: rest
post-option parameter: of
post-option parameter: the
post-option parameter: parameters