what is the use of parentheses in linux command [duplicate]

与世无争的帅哥 提交于 2020-03-06 04:52:12

问题


I run following command in Linux terminal. Can anyone tell me what is the use of parentheses in Linux terminal and following command also ?

$(echo "GET / HTTP/1.0";echo "Host: www.google.com"; echo) | nc www.google.com 80


回答1:


( list )
Placing a list of commands between parentheses causes a subshell environment to be created, and each of the commands in list to be executed in that subshell. Since the list is executed in a subshell, variable assignments do not remain in effect after the subshell completes.




回答2:


Parentheses denote a subshell in bash. In your command, the $() is command substitution and if it is like () is a subshell. Both of them run commands, the difference is what happens to the output.

Unix & Linux Answer



来源:https://stackoverflow.com/questions/45749989/what-is-the-use-of-parentheses-in-linux-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!