我使用 wget
从 example.com 下载一些 shell 脚本,并通过管道将 wget
的标准输出流式传输到标准输入来立即执行它sh
命令。
wget -O - http://example.com/myscript.sh | sh -
如何将参数传递给脚本?
最佳答案
调用 bash
时需要使用 -s
选项将参数传递给正在下载的 shell 脚本:
wget -O - http://example.com/myscript.sh | bash -s 'arg1' 'arg2'
根据man bash
:
-s If the -s option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell.
关于linux - 如何将参数传递给 sh 从 stdin 读取的脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41120534/