Results 1 to 4 of 4
I'm having trouble with the following line:
Code:
if [ "$verbose" -eq "$TRUE" ] ; then ...
It gives me
Code:
line 22: [: : integer expression expected
but still ...
- 08-03-2007 #1Just Joined!
- Join Date
- Jul 2007
- Posts
- 15
bash if-statement issues
I'm having trouble with the following line:
It gives meCode:if [ "$verbose" -eq "$TRUE" ] ; then ...
but still displays the results I need.Code:line 22: [: : integer expression expected
Here's a sample of the output:
Here's the full source:Code:[~/Research/hiv/boronated-inhibitors/docked-top-poses] $ m2dc ~/scripts/m2dc: line 22: [: : integer expression expected 3.89480383844937690078 ~/scripts/m2dc: line 22: [: : integer expression expected 3.94594374389701607666
The "vd", and "m2distances" are scripts that I wrote while fiddling around with awk. vd finds the distance between two points in 3d space and m2 distances uses awk to extract their coordinates out of a .mol2 file.Code:#!/bin/bash let TRUE=0 let FALSE=1 if [ "$1" == "-v" ] ; then verbose=0 fi let counter=0 for file in `ls -1 *.mol2` ; do array[$counter]=$file let counter=$counter+1 done let n=0 for (( i=0; i<$counter; i++ )) ; do for (( j=$i+1; j<$counter; j++ )) ; do let n=$n+1 distance=$(vd $(m2distances ${array[$i]}) $(m2distances ${array[$j]})) if [ "$verbose" -eq "$TRUE" ] ; then echo "$n: Comparing: ${array[$i]}: to: ${array[$j]}: $distance" > /dev/stdout else echo $distance > /dev/stdout fi done done echo echo "$n comparisons done."
I'm pretty new to scripting, so any help/ideas/tips would be appreciated.
Thanks.
- 08-04-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
The reason for the error is that if $1 is not "-v" the variable $verbose is not set, replace this:
with:Code:if [ "$1" == "-v" ] ; then verbose=0 fi
RegardsCode:if [ "$1" == "-v" ] ; then verbose=0 else verbose=1 fi
- 08-04-2007 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Does this example help you?
producing:Code:#!/bin/bash # @(#) s1 Demonstrate useful debugging technique. echo echo "GNU bash $BASH_VERSION" >&2 # Define function to test value of variable "verbose". check() { if [ "$verbose" -eq "$TRUE" ] then echo " verbose was true." elif [ "$verbose" -eq "$FALSE" ] then echo " verbose was false." else echo " verbose set to unknown value." fi } let TRUE=0 let FALSE=1 verbose="$TRUE" echo echo " First invocation:" check unset verbose echo echo " Second invocation:" check set -o nounset echo echo " Third invocation:" check exit 0
cheers, drlCode:% ./s1 GNU bash 2.05b.0(1)-release First invocation: verbose was true. Second invocation: ./s1: line 11: [: : integer expression expected ./s1: line 14: [: : integer expression expected verbose set to unknown value. Third invocation: ./s1: line 11: verbose: unbound variable
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 )
- 08-04-2007 #4Just Joined!
- Join Date
- Jul 2007
- Posts
- 15


Reply With Quote
