Hi everyone!
I'm trying to validate two values in an If.
One value is saved in a variable and the other is hardcoded.
I'm using:
if [ $valu_saved -ne 44 and $myvalue == -1 ]
then
The variable $myvalue was set using:
myvalue=-1
I have tried using;
-ne -1
, is not working as well.
Could you please give a hand here?
Thank you!
Scott
May 13, 2011, 7:17pm
2
Your syntax is just a bit muddled up:
if [ $valu_saved -ne 44 -a $myvalue -eq -1 ]
But I don't know, really, what you mean by "hardcoded" in relation to $valu_saved. Where is it set?
The use of -a in a test statement is deprecated. Use:
if [ $valu_saved -ne 44 ] && [ $myvalue -eq -1 ]
or, if you are using a modern shell (bash, zsh, ksh93, etc0
#!/usr/local/bin/bash
valu_saved=43
myvalue=-1
if (( valu_saved != 44 && myvalue == -1 ))
then
echo "valid"
fi
Scott
May 14, 2011, 6:12pm
5
Can you please show me where it is described that this is deprecated? I checked with the Open Group definition of test before posting, and -a is not described as deprecated there.
I'm now using:
if [ $valu_saved -ne 44 -a $myvalue -eq -1 ]
It is now working!
Thank you all!