linux - Is there any difference between the three assignment ways: a=1, let a=1, ((a=1)) -


consider 3 ways assign value:

#!/bin/bash  a=1 let a=1 ((a=1)) 

are 3 assignments totally equal?

if shell has non-posix extensions (ie. ksh or bash), they're entirely equivalent: a=1 string assignment, whereas let a=1 , (( a=1 )) numeric assignments, gets stored in a string representing number 1 in every case.

$(( )) posix-compliant way create math context. (( )) , let, contrast, not specified posix, extensions available in shells go beyond standard.


now, consider instead:

b=2           # result  | posix?  | type               | comments          # --------+---------+--------------------+---------------- a=b      # a=b     | true    | string assignment  | let a=b  # a=2     | false   | numeric assignment | ancient non-posix syntax a=$((b)) # a=2     | true    | numeric assignment | modern posix syntax ((a=b))  # a=2     | false   | numeric assignment | modern non-posix extension 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -