Hey guys,
a=`cat abc | wc -l`
b=`cat def | wc -l`
if $a== $b
then
echo "a"
else
echo "b"
fi
I want the if condition to retry itself , untill a==b.
I can't use goto statemt.
Please help.
Thanx in advance.
Hey guys,
a=`cat abc | wc -l`
b=`cat def | wc -l`
if $a== $b
then
echo "a"
else
echo "b"
fi
I want the if condition to retry itself , untill a==b.
I can't use goto statemt.
Please help.
Thanx in advance.
while true
do
if [ $a == $b ]
then
echo "a"
break
else
echo "b"
fi
done
Hey,
I need to retry the if condition.
The count in a and b may vary with time.
So if he count of both the files is different, then my else condition will work.
I need the if condition to retry itself, until there is a change in count of a and b so that i reach the else condition.
while true
do
a=`wc -l <abc`
b=`wc -l <def`
if [ $a == $b ]
then
echo "a"
break
else
echo "b"
break
fi
sleep 5 # Sleep for 5 seconds before retry
done
Jean-Pierre.
Here's my 2 cents using ksh93 on Solaris:
#!/usr/dt/bin/dtksh
#Declare constants
typeset -r FILE1=abc
typeset -r FILE2=def
# Declare integer variables.
typeset -i a
typeset -i b
# Loop forever (could be risky, but that was the requirement).
while :
do
# Make sure both fles exist and have size.
if [[ -s $FILE1 ]] && [[ -s $FILE2 ]]; then
# Count lines in each file.
a=$(wc -l < $FILE1)
b=$(wc -l < $FILE2)
if (( $a == $b )); then
print "a"
break
else
print "b"
sleep 2
fi
else
print "File $FILE1 or $FILE2 does not exist"
exit 1
fi
done
exit 0
Its not workin aegsis.
I need retry the if condition and once the if condition is not satisfied i need to go to the else condtion and end the script.