bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is bash dying or dead (was Re: 4.1 is "$((( ))) an 'official operator, i


From: Dennis Williamson
Subject: Is bash dying or dead (was Re: 4.1 is "$((( ))) an 'official operator, if $(( )) isn't?
Date: Wed, 10 Aug 2011 21:11:18 -0500

>
> I thought the $( ) was necessary to make the inner (()) an arithmetic
> expression...  Does it execute in a sub process?
>

No, $( ) is for process substitution, $(( )) is for an arithmetic context.

I normally (in Bash), use (( )) outside the whole expression since it
gives me complete freedom of placement of spacing and eliminates the
need for dollar signs (in most cases). It also makes increment and
similar operators available.

(( arrayA[foo]  =  arrayB[bar] ** 3 / baz ))
(( arrayB[bar]  -=  qux ))
(( qux++ ))

A demonstration of various combinations of spaces and parentheses.

$ echo $(((3+2)))
5
$ echo $(( (3+2) ))
5
$ echo $( ( (3+2) ) )
3+2: command not found

$ echo $( ((3+2)) )

$ echo $((3+2))
5
$ echo $( (3+2) )
3+2: command not found

$ echo $(( 3+2 ))
5
$ echo $(( 3+ 2 ))
5
$ echo $(( 3 + 2 ))
5
$ echo $( 3+2 )
3+2: command not found

--
Visit serverfault.com to get your system administration questions answered.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]