All,
My environment is Red Hat Enterprise Linux 5.
I am using the following condition --
if [[ $z -gt 5 -a $z -lt 7 ] -0 [ $y == 'VALID' ]]
above command is not working. It is telling that -a unexpected.
Please help me
All,
My environment is Red Hat Enterprise Linux 5.
I am using the following condition --
if [[ $z -gt 5 -a $z -lt 7 ] -0 [ $y == 'VALID' ]]
above command is not working. It is telling that -a unexpected.
Please help me
You're getting your ]'s and ]]'s mixed up, if you start with [[ always end with ]], they're not nesting brackets.
Hi
I tried with following combinations,
if [[ $z -gt 5 -a $z -lt 7 ] -o [ $y == 'VALID' ]]
if [ $z -gt 5 -a $z -lt 7 -o $y == 'VALID' ]
if [ $z -gt 5 ]-a [ $z -lt 7 ] -0 [ $y == 'VALID' ]
nothing is working fine.
Can you please provide the correct one
How about ...
if ([ $z -gt 5 ] && [ $z -lt 7 ]) || [ $y == 'VALID' ]
still not working..
Try this. The condition is the same each time, we just change the data for each test.
z=6
y="VALID"
if [ \( ${z} -gt 5 -a ${z} -lt 7 \) -o \( "${y}" = "VALID" \) ]
then
echo "TRUE: ${z} ${y}"
else
echo "FALSE: ${z} ${y}"
fi
z=5
y="VALID"
if [ \( ${z} -gt 5 -a ${z} -lt 7 \) -o \( "${y}" = "VALID" \) ]
then
echo "TRUE: ${z} ${y}"
else
echo "FALSE: ${z} ${y}"
fi
z=6
y="ORANGE"
if [ \( ${z} -gt 5 -a ${z} -lt 7 \) -o \( "${y}" = "VALID" \) ]
then
echo "TRUE: ${z} ${y}"
else
echo "FALSE: ${z} ${y}"
fi
z=4
y="ORANGE"
if [ \( ${z} -gt 5 -a ${z} -lt 7 \) -o \( "${y}" = "VALID" \) ]
then
echo "TRUE: ${z} ${y}"
else
echo "FALSE: ${z} ${y}"
fi
./scriptname
TRUE: 6 VALID
TRUE: 5 VALID
TRUE: 6 ORANGE
FALSE: 4 ORANGE
[house@leonov] more test.bash
#! /bin/bash
if ([ $1 -gt 5 ] && [ $1 -lt 7 ]) || [ $2 == 'VALID' ]
then
echo "true"
else
echo "false"
fi
exit 0
[house@leonov] sh test.bash 5 VALID
true
[house@leonov] sh test.bash 6 VALID
true
[house@leonov] sh test.bash 6 ORANGE
true
[house@leonov] sh test.bash 4 ORANGE
false
Lateral thought. Maybe you were just trying to validate $z ?
for z in 1 2 3 4 5 6 7 8 9
do
if [ ${z} -gt 5 -a ${z} -lt 7 ]
then
y="VALID"
else
y="INVALID"
fi
echo "${z} : ${y}"
done
./scriptname
1 : INVALID
2 : INVALID
3 : INVALID
4 : INVALID
5 : INVALID
6 : VALID
7 : INVALID
8 : INVALID
9 : INVALID
All,
I used methyl's code and is working fine. Thanks a lot for your inputs.
Psychic or what?
Clarify the problem and the solution will become clear.
(Methyl Sep 2009)
Methyl,
I said that I used your suggestion (if [ \( ${z} -gt 5 -a ${z} -lt 7 \) -o \( "${y}" = "VALID" \) ]) and it is working fine.
For that you are telling me psychic and all.
Mind your words in the forum.