AB10
1
Hi All,
I want to compare the variable value with string in a shell script.
my code is:
for var in $packsName
do
if [ $var -ne 'ABC' || $var -ne 'XYZ' ]
then
echo $var
fi
done
But I am getting error as:
ABC : not found.
Am I going wrong somwhere?
please guide.
Thanks.
for var in $packsName
do
if [ "$var" != "ABC" -o "$var" != "XYZ" ]
then
echo $var
fi
done
But I don't know if this test is really what you want to have, as it will always return true
AB10
3
What I want is, in all the values for $var, I dont want the statements to be executed for ABC and XYZ.
I tried your solution, but it still prints for ABC and XYZ.
I dont want it to be printed..
Try:
for var in $packsName
do
if [ "$var" != "ABC" -a "$var" != "XYZ" ]
then
echo $var
fi
done
AB10
5
Thanks, -a option worked.
Can you please tell me the difference between -o and -a option?
-o means logical OR, while -a is logical AND.