相关疑难解决方法(0)

我们如何运行存储在变量中的命令?

$ ls -l /tmp/test/my\ dir/
total 0
Run Code Online (Sandbox Code Playgroud)

我想知道为什么以下运行上述命令的方法失败或成功?

$ abc='ls -l "/tmp/test/my dir"'

$ $abc
ls: cannot access '"/tmp/test/my': No such file or directory
ls: cannot access 'dir"': No such file or directory

$ "$abc"
bash: ls -l "/tmp/test/my dir": No such file or directory

$ bash -c $abc
'my dir'

$ bash -c "$abc"
total 0

$ eval $abc
total 0

$ eval "$abc"
total 0
Run Code Online (Sandbox Code Playgroud)

shell bash quoting variable

104
推荐指数
2
解决办法
13万
查看次数

使用管道馈送源命令

以前我使用过这样的source命令:

source file_name
Run Code Online (Sandbox Code Playgroud)

但我想要做的是:

echo something | source
Run Code Online (Sandbox Code Playgroud)

哪个不起作用。

shell pipe

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

标签 统计

shell ×2

bash ×1

pipe ×1

quoting ×1

variable ×1