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 empty – Romeo Ninov Jun 02 '23 at 05:02sh
, not withbash
. – Kusalananda Jun 02 '23 at 05:05sh
instead of abash
. – Marc Le Bihan Jun 02 '23 at 05:29[ "a" != "a" -a "b" != "b" ]
is the way to combine tests with-a
based onman [
. The alternate to[ EXPR ]
,test EXPR
can also be used as well, you can check from the command line:test "a" = "a" -a "b" = "b"; echo $?
– chexum Jun 02 '23 at 06:17-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. – Kusalananda Jun 02 '23 at 06:22fgrep
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. – Kusalananda Jun 02 '23 at 06:34