Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在执行以下命令时,我得到输出为i-56816733
i-56816733
str=$" $(wget -q -O- http://169.254.169.254/latest/meta-data/instance-id)" echo $str
str=$" $(wget -q -O- http://169.254.169.254/latest/meta-data/instance-id)"
echo $str
但我想在终端上使用 $ 符号打印“str”变量中存在的整个命令,如下所示:-
$(wget -q -O- http://169.254.169.254/latest/meta-data/instance-id)
我想要上面的输出使用'echo'我怎么能得到?
只需使用单引号:
str='$(wget -q -O- http://169.254.169.254/latest/meta-data/instance-id)'
如果你想要插值有两种方法,你可以附加各种单引号字符串:
str='$(mkdir'$1')'
或者,您可以转义您想要文字的美元符号并使用双引号:
str="\$(mkdir $1)"