Results 1 to 8 of 8
I have a redhat bash script and the elif will not work. Any ideas?
At marc4 the $v_countRpts val is 0 and so is the $v_return_ssh value, but the code ...
- 02-26-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 3
elif won't work!
I have a redhat bash script and the elif will not work. Any ideas?
At marc4 the $v_countRpts val is 0 and so is the $v_return_ssh value, but the code will alway enter the elif block, i cannot see why.
echo "marc4"
echo "$v_countRpts"
echo "$v_return_ssh"
if [ $v_return_ssh = 1 ]
then
echo "marc5"
echo "$v_countRpts"
echo "$v_return_ssh"
i=`expr $file_length + 1`
echo "#### Exiting batch call loop due to error in ${bat_file} "
return 1
elif [ $v_return_ssh = 0 ] && [ $v_countRpts > 0 ]
then
# poll the same schedule again if not ready.
i=`expr $i + 0`
m=`expr $m + 1`
echo "marc6"
echo "$v_countRpts"
echo "$v_return_ssh"
else
echo "marc7"
echo "$v_countRpts"
echo "$v_return_ssh"
# poll the next schedule.
i=`expr $i + 1`
m=`expr $m + 1`
fi
else
echo "marc8"
echo "$v_countRpts"
echo "$v_return_ssh"
# poll the next flexi schedule.
i=`expr $i + 1`
m=`expr $m + 1`
fi
- 02-26-2008 #2
Suggestion:
Whip up the simplest five-liner script possible which uses elif, and see whether it works.
If it works, then take a debug copy of your longer script and start removing stuff until it looks like the simple five-liner. Along the way, it should start working. What you had to remove to get it to work will be your clue.
If it doesn't work, post the simple five-liner here.--
Bill
Old age and treachery will overcome youth and skill.
- 02-26-2008 #3Just Joined!
- Join Date
- Feb 2008
- Posts
- 3
I got it by simly adding '-gt' instead of '>' in the elif statement! I am very new to Linux and don;t quite know the standard. For any of the tests above I also added '==' instead of '=' as I don't know the 'formal' approach. Are there any guidelines as there is a mixture of ==, =, >, 'gt etc etc in this script.
- 02-26-2008 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Escape the ">" in the elif statement:
RegardsCode:elif [ $v_return_ssh = 0 ] && [ $v_countRpts \> 0 ]
- 02-26-2008 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
You have a point on this, I may refer to this document:
http://tldp.org/LDP/abs/html/comparison-ops.html
Regards
- 02-26-2008 #6Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
The double-bracket syntax effectively quotes the ">" symbol. The single-bracket causes a file to be created:
Producing:Code:#!/bin/bash - # @(#) s1 Demonstrate arithmetic comparison, quoting within [[ ]]. echo "(Versions displayed with local utility \"version\")" version >/dev/null 2>&1 && version =o $(_eat $0 $1) a=1 b=2 rm -f 2 set -o noclobber touch 2 echo echo " Double brackets:" if [[ $a > $b ]] then echo " Value $a is greater than $b." else echo " Value $b is greater than $a." fi echo echo " Single brackets with -gt:" if [ $a -gt $b ] then echo " Value $a is greater than $b." else echo " Value $b is greater than $a." fi echo echo " Single brackets with >:" if [ $a > $b ] then echo " Value $a is greater than $b." else echo " Value $b is greater than $a." fi exit 0
The double-bracket syntax has other advantages, but this one seems very useful in contexts such as this ... cheers, drlCode:% ./s1 (Versions displayed with local utility "version") Linux 2.6.11-x1 GNU bash 2.05b.0 Double brackets: Value 2 is greater than 1. Single brackets with -gt: Value 2 is greater than 1. Single brackets with >: ./s1: line 35: 2: cannot overwrite existing file Value 2 is greater than 1.
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 02-27-2008 #7Just Joined!
- Join Date
- Feb 2008
- Posts
- 3
thanks all, can you recommend a linux book(covering starter to advanced) but something with very easy to follow and find references please.
- 02-27-2008 #8Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
There are also excellent online tutorials, just Google for "bash tutorial", 2 links:
BASH Programming - Introduction HOW-TO
http://tldp.org/LDP/abs/html/
Regards


Reply With Quote
