D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

RE: [LUG] Long bash scripts - buglet

 

Title: RE: [LUG] Long bash scripts - buglet

I just spotted a small problem, [ $jump < 40 ] does a textual comparison, not a numeric one, and  [[ would not have helped.  For a numeric comparison use double parentheses, to illustrate try this:

line=9
if [ $line < 40 ]
then
   echo "OK"
else
   echo "Doh!"
fi

if (( $line < 40 ))
then
   echo "OK"
else
   echo "Doh!"
fi

Alternatively use the comparison operator lt.
 
Clive

-----Original Message-----
From: Neil Williams [mailto:linux@xxxxxxxxxxxxxx]
Sent: Tuesday, January 25, 2005 8:23 AM
To: DCGLUG list
Subject: Re: [LUG] Long bash scripts


On Tuesday 25 January 2005 7:45 am, Darke, Clive wrote:
>  >I'm not using goto, I'm using if [ $jump < 40 ] then
> ...
> fi
>
> Why do so few people use double brackets? [[ ... ]] are so much more
> powerful than Bourne style singles.

Don't know, I've never used double. Come to that, I haven't come across a bash
script that I needed to edit that used double either.

> This might be a good case for restructuring the code around functions...
>
> Clive

This isn't a big deal, it's a personal let's-save-some-time script that stops
me having to sit here waiting for 2 consecutive export+build operations of 4
different projects with rudimentary error handling. If you feel it would be a
lot better with functions, by all means take a look at the code as it is now
- the single bracket version will be in the next tarball, the current version
has to be run from the beginning every time:
http://code.neil.williamsleesmill.me.uk/qofqsf.html#AEN212
Tarball: qof-qsf14-01-05.tar.gz (148K)
Signature qof-qsf14-01-05.tar.gz.asc
patches/scripts/working/automate.sh

The next tarball should be ready today, it'll be listed on the same page when
ready.

Let me know. Currently, there are only two people needing the script and one
of those would have to edit the multiple cd calls to his filesystem. The next
version really should use a $prefix that is set in the script so that it's
only one edit.

--

Neil Williams
=============
http://www.dcglug.org.uk/
http://www.nosoftwarepatents.com/
http://sourceforge.net/projects/isbnsearch/
http://www.neil.williamsleesmill.me.uk/
http://www.biglumber.com/x/web?qs=0x8801094A28BCB3E3


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________