Interpreting command substitution from a variable in bash

随声附和 提交于 2019-12-24 11:03:47

问题


For the following value of FOO:

$ FOO='echo `echo hello`'
$ $FOO
`echo hello`

how can I get the expected output:

hello

Basically, how can I interpret a command substitution in the contents of a variable?


回答1:


Answering the question as given,

eval $FOO

but you're probably going about your real problem the wrong way.




回答2:


Try this

$ FOO="echo `echo hello`"
$ $FOO 

Just replace single quotes with double quotes.



来源:https://stackoverflow.com/questions/11531332/interpreting-command-substitution-from-a-variable-in-bash

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