Double parenthesis with and without dollar

后端 未结 2 383
野性不改
野性不改 2021-01-29 17:11

Is $(...) the same as (...) in Bash?

Also, is $((...)) the same as ((...))?

Also, is ${...} the sa

2条回答
  •  误落风尘
    2021-01-29 17:57

    Adding to the answer above:

    1. [..] is used in conditions or logical expressions. Example:
    $ VAR=2
    $ if [ $VAR -eq 2 ]
    
    > then
    > echo 'yes'
    > fi
    yes
    
    1. [[...]] offers extended functionality to single square brackets. Particularly, it is useful for =~ operator (used in regular expressions). Example:
    $ VAR='some string'
    $ if [[ $VAR =~ [a-z] ]]; then
    > echo 'is alphabetic'
    > fi
    is alphabetic
    

    Reference:

    https://linuxconfig.org/bash-scripting-parenthesis-explained

提交回复
热议问题