Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: '$(( ))' means 'expr' and '[ ]' means 'test'?

Tags:

linux

bash

I have been working with some bash scripting lately and been looking through the man pages. From what I have gathered, does $(( )) mean expr and [ ] mean test?

For $(( )):

echo $(( 5 + 3 ))

has the same output as:

echo $(expr 5 + 3)

For [ ]:

test 'str' = 'str'

has the same success value as:

[ 'str' = 'str' ]

Did I get my understanding right?

like image 483
Vern Avatar asked May 23 '12 10:05

Vern


1 Answers

the ((...)) construct is equivalent to the bash builtin let. let does mostly the same stuff which expr does.

the $((...)) construct, note the $ at the beginning, will substitute the output of the expression inside just like $(...) does.

the [...] construct is in fact just another name for test.

see the bash help pages for more information.

  • help "("
  • help let
  • help [
  • help test

see also:

  • http://mywiki.wooledge.org/BashFAQ/031
  • http://mywiki.wooledge.org/ArithmeticExpression
like image 142
Lesmana Avatar answered Oct 07 '22 09:10

Lesmana