linux - 如何将参数传递给 sh 从 stdin 读取的脚本?

标签 linux bash shell

我使用 wgetexample.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/

相关文章:

bash - 如何根据语言环境变量格式化 float 以供显示?

Bash:从函数返回行号

linux - 如何在多个文件中运行多年和 12 个日历月的时间戳?

PHP 主机名绑定(bind)

c++ - 使用 linux 操作内存中的位图图像

linux - 读取日志文件并获取两个日期之间的条目

linux - .so在linux下注入(inject): how to locate address of dlopen()?

linux - 从一个参数和仅一个参数获取输入

Linux find -exec 权限被拒绝

linux - 运行 while 循环直到后台进程完成它的工作