Double parenthesis with and without dollar

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

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

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

Also, is ${...} the sa

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-29 18:03

    • $(...) means execute the command in the parens in a subshell and return its stdout. Example:

      $ echo "The current date is $(date)"
      The current date is Mon Jul  6 14:27:59 PDT 2015
      
    • (...) means run the commands listed in the parens in a subshell. Example:

      $ a=1; (a=2; echo "inside: a=$a"); echo "outside: a=$a"
      inside: a=2
      outside: a=1
      
    • $((...)) means perform arithmetic and return the result of the calculation. Example:

      $ a=$((2+3)); echo "a=$a"
      a=5
      
    • ((...)) means perform arithmetic, possibly changing the values of shell variables, but don't return its result. Example:

      $ ((a=2+3)); echo "a=$a"
      a=5
      
    • ${...} means return the value of the shell variable named in the braces. Example:

      $ echo ${SHELL}
      /bin/bash
      
    • {...} means execute the commands in the braces as a group. Example:

      $ false || { echo "We failed"; exit 1; }
      We failed
      

    More generally what does the dollar sign stand for?

    It means whatever it means in the given context.

提交回复
热议问题