如何将参数传递给输入到 bash 的脚本

k06*_*06a 12 bash pipe input curl

现在我有这样的单线:

curl -fsSL http://git.io/vvZMn | bash
Run Code Online (Sandbox Code Playgroud)

它正在下载脚本并将其作为标准输入文件传递给 bash。我想用附加参数运行这个脚本print

也许是这样的?

curl -fsSL http://git.io/vvZMn | bash -- print
Run Code Online (Sandbox Code Playgroud)

但这不起作用。

Joh*_*024 18

我相信您正在寻找的是-s选项。使用-s,您可以将参数传递给脚本。

作为一个虚拟示例来说明这一点:

$ echo 'echo 1=$1' | bash -s -- Print
1=Print
Run Code Online (Sandbox Code Playgroud)

在这里,您可以看到 stdin 上提供的脚本被赋予了位置参数Print。您的脚本需要一个-u UUID参数,也可以容纳它:

$ echo 'echo arguments=$*' | bash -s -- -u UUID print
arguments=-u UUID print
Run Code Online (Sandbox Code Playgroud)

所以,在你的情况下:

curl -fsSL http://git.io/vvZMn | bash -s -- print
Run Code Online (Sandbox Code Playgroud)

或者,

curl -fsSL http://git.io/vvZMn | bash -s -- -u UUID print
Run Code Online (Sandbox Code Playgroud)

正如斯蒂芬哈里斯指出的那样,下载脚本并在看不见的情况下执行它是一个安全问题。