Bash – $(( )) vs. $[]

Oliver Grawert ogra at ubuntu.com
Mon Dec 3 17:21:11 UTC 2012


hi
On Mo, 2012-12-03 at 18:02 +0100, Johnny Rosenberg wrote:
> ~$ a=3
> ~$ b=4
> ~$ echo $(($a+$b))
> 7
> ~$ echo $[$a+$b]
> 7
> ~$
> 
> 
> So are these syntaxes equivalent? If not, what are the differences?

they are in bash, the $[] is bash specific style here. 

but they arent in POSIX compliant shells (like the system shell of
ubuntu (dash))


ogra at chromebook:~$ /bin/sh
$ a=1
$ b=2
$ echo $[$a+$b]
$[1+2]
$ echo $(($a+$b))
3
$ 
ogra at chromebook:~$

ciao
	oli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20121203/e3641c99/attachment.sig>


More information about the ubuntu-users mailing list