带或不带美元的双括号 [英] Double parenthesis with and without dollar

查看:74
本文介绍了带或不带美元的双括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bash中的$(...)(...)相同吗? $((...))((...))一样吗? ${...}{...}一样吗?一般来说,美元符号代表什么?谢谢.

Is $(...) the same as (...) in bash? Also is $((...)) the same as ((...))? Also is ${...} the same as {...}? More generally what does the dollar sign stand for? Thank you.

推荐答案

  • $(...)表示在子外壳的paren中执行命令并返回其stdout.示例:

    • $(...) 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
      

    • ((...))表示执行算术运算,可能会更改Shell变量的值,但不返回其结果.示例:

    • ((...)) 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
      

    • ${...}表示返回括号中命名的shell变量的值.示例:

    • ${...} 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.

      这篇关于带或不带美元的双括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆