bash bash中括号${}、$()、$[]的区别和用法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17992711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:05:56  来源:igfitidea点击:

Brackets ${}, $(), $[] difference and usage in bash

bash

提问by yart

Bash contains different braces and they used differently. Could you please explain comprehensively what is difference between ${}, $()and $[]? Where they are used in bash? What is their main purpose?

Bash 包含不同的大括号,它们的用法也不同。您能否全面解释一下${},$()和之间的区别$[]?它们用于 bash 的哪些地方?他们的主要目的是什么?

回答by user1146332

The keyword is shell expansion! So i highly recommend you to read the section Shell Expansionsin your bash reference manual.

关键词是shell expansion!所以我强烈建议您阅读Shell Expansionsbash 参考手册中的部分。

You can access this section online [1].

您可以在线访问此部分 [1]。

The names of the following stated forms are:

下列表格的名称是:

  • ${}Parameter expansion
  • $()Command substitution
  • ${}参数扩展
  • $()命令替换

the form $[]isn't actually stated in the manual so i wouldn't use it.

该表格$[]实际上并未在手册中说明,所以我不会使用它。

[1] http://www.gnu.org/software/bash/manual/bashref.html#Shell-Expansions

[1] http://www.gnu.org/software/bash/manual/bashref.html#Shell-Expansions