shell -- 变量做命令执行

xiaoxiao2021-02-27  404

user@ubuntu cmd $ ls && echo 1 a.txt 1 user@ubuntu cmd $ bin="ls && echo 1" user@ubuntu cmd $ ${bin} ls: cannot access &&: No such file or directory ls: cannot access echo: No such file or directory ls: cannot access 1: No such file or directory

变量做命令执行时,shell自动将 ‘;’ 、’&&’等 使用”进行了限制,命令无法直接展开执行。

user$@ubuntu cmd $ str=$(eval ${bin});echo ${str} a.txt 1

eval 命令将会首先扫描命令行进行所有的置换,然后再执行该命令。

转载请注明原文地址: https://www.6miu.com/read-5567.html

最新回复(0)