有没有办法将以下内容组合成一个漂亮的“单衬”:
echo "free -m" > /tmp/dC4v2cK
bash /tmp/dC4v2cK
Run Code Online (Sandbox Code Playgroud)
我认为您正在寻找eval
(如foo='free -m'; eval $foo
)。请记住,如果$foo
来自不受信任的来源,那么做这样的事情会带来安全隐患,那么您可能会无意中做坏事。例如,如果有人设法让这条线发生怎么办。 foo='rm -rf /'
$ help eval
eval: eval [arg ...]
Execute arguments as a shell command.
Combine ARGs into a single string, use the result as input to the shell,
and execute the resulting commands.
Exit Status:
Returns exit status of command or success if command is null.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
670 次 |
最近记录: |