Hi
how to write this:
if [ $x different from these 2 strings: 'A' or 'B' ]
then
usage
fi
thx
Hi
how to write this:
if [ $x different from these 2 strings: 'A' or 'B' ]
then
usage
fi
thx
if [[ $x != "A" || $x != "B" ]]
more here Other Comparison Operators
and Nested if/then Condition Tests
Please use code tags.
hi
...
echo $x
if [[ "$x" != "A" || "$x" != "B" ]]
then
fct
else
echo OK
fi
...
the output is:
A
fct output (another echo)
any idea?
The Boolean needs to be: (NOT = A) AND (NOT = B).
For example:
#!/bin/ksh
x="$1"
#
echo $x
if [[ ! "$x" = "A" && ! "$x" = "B" ]]
then
echo fct
else
echo OK
fi
However this is brain damage to follow in scripts.
IMHO a case statement is easier to follow for basic validation.
#!/bin/ksh
x="$1"
#
case "${x}" in
"A"|"B")
echo "Valid value: ${x}"
continue
;;
*)
echo "Invalid value: ${x}"
exit
;;
esac