Bash - 如何将参数传递给通过标准输入读取的脚本

标签 bash

我正在尝试从标准输入执行脚本并将参数传递给它。有办法吗?

假设我有以下内容:

cat script.sh | bash

我如何将参数传递给脚本?

我不想这样做:

bash script.sh arguments

也不是这个:

./script.sh arguments

最佳答案

在 Linux 上,

cat script.sh | bash /dev/stdin arguments

似乎有效。

关于Bash - 如何将参数传递给通过标准输入读取的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8514284/

相关文章:

linux - 如何使用 Shell 脚本读取包含具有句点字符的键的 .properties 文件

Bash 模板 : How to build configuration files from templates with Bash?

python - 如何防止在 python 退出时在 bash 中执行按键

regex - 如何循环遍历与 unix shell 脚本中的正则表达式匹配的文件

bash - 有效地检查几个命令的 Bash 退出状态

bash - 在谷歌云上的 bash 中获取正确的 $HOME 目录

linux - 查找某个目录下所有正在运行的脚本

bash - 如何使用 sed、awk 或同时使用这两种工具从 dig 查询中提取 mx 记录

python - 自动ssh进入服务器的脚本

python - 如何使用子进程在Python中访问Bash环境变量?