In a bash script, I'm willing to check if a parameter has a boolean value ("true" or "false").
I'm attempting this in two scripts in two different ways, both failing.
I've checked many Stack Exchange hints, and I believe doing what I should, but it isn't the case.
if [ "$2" != "true" ] -a [ "$2" != "false" ]; then
echo "Indiquez si Geoserver est en installation initiale (false) ou update (true)" >&2;
exit 1;
fi
fails with the message Geoserver.sh: 12: [: true: unexpected operator
if [[ "$3" != "true" && "$3" != "false" ]]; then
echo "Indiquez si Kafka est en installation initiale (false) ou update (true)" >&2;
exit 1;
fi
fails with Kafka.sh: 18: [[: not found
if [ "$2"z != "true" ] -a [ "$2" != "false"z ]; then
. ANd usually inif
are user&&
and||
for AND and OR. And the reason for the error for me is$2
is emptysh
, not withbash
.sh
instead of abash
.-a
and-o
are marked obsolete in the POSIX standard (see the "APPLICATION USAGE" section here). It's too difficult to write unambiguous code with them.fgrep
andegrep
, adding standard options togrep
did sound better than having a proliferation of utilities that do essentially the same thing, but I agree that muscle memory is difficult to re-train.