我从example.com下载了一些shell脚本,wget并wget通过管道传输stdout 到sh命令的stdin 立即执行它.
wget -O - http://example.com/myscript.sh | sh -
如何将参数传递给脚本?
uup*_*cal 13
虽然接受的答案是正确的,但它只能按初始发帖者的要求起作用bash,而不能起作用。sh
要执行此操作,sh您必须添加--:
curl https://example.com/script.sh | sh -s -- --my-arg
Run Code Online (Sandbox Code Playgroud)
您需要-s在调用bash时将选项用于将参数传递给正在下载的shell脚本:
wget -O - http://example.com/myscript.sh | bash -s 'arg1' 'arg2'
Run Code Online (Sandbox Code Playgroud)
按照man bash:
Run Code Online (Sandbox Code Playgroud)-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.