command-substitution

When does command substitution spawn more subshells than the same commands in isolation?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 18:06:10
问题 Yesterday it was suggested to me that using command substitution in bash causes an unnecessary subshell to be spawned. The advice was specific to this use case: # Extra subshell spawned foo=$(command; echo $?) # No extra subshell command foo=$? As best I can figure this appears to be correct for this use case. However, a quick search trying to verify this leads to reams of confusing and contradictory advice. It seems popular wisdom says ALL usage of command substitution will spawn a subshell.

How to address error “bash: !d': event not found” in Bash command substitution [duplicate]

我只是一个虾纸丫 提交于 2019-11-26 17:57:48
This question already has an answer here: echo “#!” fails — “event not found” 5 answers I am attempting to parse the output of a VNC server startup event and have run into a problem in parsing using sed in a command substitution. Specifically, the remote VNC server is started in a manner such as the following: address1="user1@lxplus.cern.ch" VNCServerResponse="$(ssh "${address1}" 'vncserver' 2>&1)" The standard error output produced in this startup event is then to be parsed in order to extract the server and display information. At this point the content of the variable VNCServerResponse is

How to address error “bash: !d': event not found” in Bash command substitution [duplicate]

痞子三分冷 提交于 2019-11-26 04:55:06
问题 This question already has an answer here: echo “#!” fails — “event not found” 5 answers I am attempting to parse the output of a VNC server startup event and have run into a problem in parsing using sed in a command substitution. Specifically, the remote VNC server is started in a manner such as the following: address1=\"user1@lxplus.cern.ch\" VNCServerResponse=\"$(ssh \"${address1}\" \'vncserver\' 2>&1)\" The standard error output produced in this startup event is then to be parsed in order