LWN.net Logo

shell arithmetic is not a "bashism"

shell arithmetic is not a "bashism"

Posted Aug 7, 2009 16:02 UTC (Fri) by vapier (subscriber, #15768)
Parent article: A tale of two shells: bash or dash

The article lists "shell arithmetic" as a "bashism", but that is obviously incorrect:
http://www.opengroup.org/onlinepubs/9699919799/utilities/...

dash has had a history of not supporting all of POSIX's math requirements (like `v=1; echo $((v))`), but that should be fixed now (if not by dash, then by distros).


(Log in to post comments)

shell arithmetic is not a "bashism"

Posted Aug 7, 2009 20:34 UTC (Fri) by branden (subscriber, #7029) [Link]

It depends on which kind of shell arithmetic you're talking about.

The article's author may have been thinking of:

bash$ if (( 2 + 2 )); then echo yes; fi
yes

ash$ if (( 2 + 2 )); then echo yes; fi
ash: 2: not found

As the bash manpage notes, "This is exactly equivalent to let "expression"."

"let" isn't SUSv3, so (( )) isn't either.

You are probably thinking of:

$ echo $(( 2 + 2 ))
4

Which *is* SUSv3.

shell arithmetic is not a "bashism"

Posted Sep 4, 2009 10:32 UTC (Fri) by vapier (subscriber, #15768) [Link]

really you just backed up my point. while bash does have arithmetical extensions, the phrase used in the article is wrong. you cant lump "shell arithmetic" in with "let", "source", and "echo -e".

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds