小编Inf*_*per的帖子

bash 中包含命令替换的变量

我试图了解 bash 中的 shell 扩展(GNU bash,版本 4.4.20(1)-release (i686-pc-linux-gnu))。

在我的交互式 bash shell 中输入

x='$(id)'
$x
$(echo $x)
Run Code Online (Sandbox Code Playgroud)

我预计最后两行中的任何一行都会出现以下形式的错误

bash: uid=xxx(user): command not found

但得到了

bash: $(id): command not found

我不明白为什么这里不发生命令替换。不是应该通过变量扩展来实现吗?我的猜测是,它与此处描述的 Shell 操作有关https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Operation

有人可以解释这种行为吗?

我只是有兴趣更准确地理解 bash 扩展。我对在我的问题中运行实际脚本不感兴趣。

bash

2
推荐指数
1
解决办法
1647
查看次数

标签 统计

bash ×1