BASH question
Chris F.A. Johnson
chris-E7bvbYbpR6jSUeElwK9/Pw at public.gmane.org
Fri Jun 11 19:42:50 UTC 2010
On Fri, 11 Jun 2010, 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' ]
> 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?
The standard is a single =; bash also accepts ==.
When there is no improvement (functionality or efficiency) gained
by the bash-specific form, I always use the portable syntax.
--
Chris F.A. Johnson, <http://cfajohnson.com>
Author:
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
More information about the Legacy
mailing list