相关疑难解决方法(0)

如何从变量运行脚本命令?

我试图使用管道运行命令.

基础:

single="ls -l"
$single
Run Code Online (Sandbox Code Playgroud)

它按预期工作

管道:

multi="ls -l | grep e"
$multi
ls: |: No such file or directory
ls: grep: No such file or directory
ls: e: No such file or directory
Run Code Online (Sandbox Code Playgroud)

...没有惊喜

bash < $multi

$multi: ambiguous redirect
Run Code Online (Sandbox Code Playgroud)

接下来试试

bash $multi
/bin/ls: /bin/ls: cannot execute binary file
Run Code Online (Sandbox Code Playgroud)

只要

echo $multi > tmp.sh
bash tmp.sh
Run Code Online (Sandbox Code Playgroud)

工作.

有没有办法在不创建执行脚本的情况下执行更复杂的命令?

linux bash shell command-line

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

标签 统计

bash ×1

command-line ×1

linux ×1

shell ×1