BASH question

William Park opengeometry-FFYn/CNdgSA at public.gmane.org
Fri Jun 11 20:32:34 UTC 2010


On Fri, Jun 11, 2010 at 03:32:39PM -0400, bob 295 wrote:
> Recently some of my online students have been reporting errors surrounding the 
> if statement in the (simplified) code snip below.
> 
> ======= begin snip =========
> 
>         echo -n "Which test do you wish to run? (suggest s0001) [q to exit] "
>         read ans
>         if [ $ans == 'q' ] 

Try
    if [ "$ans" = q ]

- quote $ans, in case it's empty
- use single = inside [...]

>         then
>                 echo "got quit"
>         else
>                 echo "got $ans"
>         fi
> 
> ======  end snip ===========
> 
> My Linux in a Nutshell reference (circa 2000) claims that the double equals is 
> the proper syntax.     However, if I search online I find that a single 
> equals also works and that the double equals is a synonym for the single 
> variation.
> 
> Which is the proper form?    Was this changed in BASH?  If so when and what is 
> the recommended way to handle older and newer versions?
> 
> Thanks in advance for your help.

-- 
William

--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list