Hi all,
I have been writing a script to automate some work for myself and have come accross a problem. I cannot understand why it doesn't work, but then I am new to both Unix and Korn shell hacking! Here is the problem:
I want to interogate a file for a number and store that number in $tarVal. tarVal is then compared to another number and the appropriate action taken...
What should happen is this. When $success is zero and $tarVal is greater than 0.3 $n should be incremented by 3 and it should then leave the block - agreed? However, for some reason it doesn't! When tarVal has come in at 0.44 (for example) according to the program 0.44 is less than 0.3, so $success has 1 added to it and the newTarVal is set to tarVal (0.44)!!!
Here is the code:
<snip>
tarVal=$(grep 20000 ${truncfile}-${n}-${j}-output.txt | awk {'print $10'})
if [ $success -eq 0 ] && [ $tarVal -gt 0.3 ]; then
n=$((n + 3))
elif [ $success -eq 0 ] && [ $tarVal -le 0.3 ]; then
success=$((success + 1))
newTarVal=$tarVal
elif [ $success -gt 0 ] && [ $tarVal -le $newTarVal ]; then
success=$((success + 1))
newTarVal=$tarVal
else
success=$success
newTarVal=$newTarVal
fi
<snip>
Can ANYBODY enlighten me? I don't know whether I have got syntax wrong (although the script runs without error) or whether the problem lies in the use of the logical AND (&&) in some way? Please, please help as this has been foxing me for hours and hours now and I've tried everything I can think of.
Thanks in advance for any help offered!
alarmcall