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 inifare user&&and||for AND and OR. And the reason for the error for me is$2is empty – Romeo Ninov Jun 02 '23 at 05:02sh, not withbash. – Kusalananda Jun 02 '23 at 05:05shinstead of abash. – Marc Le Bihan Jun 02 '23 at 05:29[ "a" != "a" -a "b" != "b" ]is the way to combine tests with-abased onman [. The alternate to[ EXPR ],test EXPRcan 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-aand-oare 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:22fgrepandegrep, adding standard options togrepdid 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