【问题标题】:Pausing a script that has been piped to sh暂停已通过管道传输到 sh 的脚本
【发布时间】:2013-05-31 02:07:01
【问题描述】:

如果我跑了

echo "read -p 'test'" | sh

什么都没有发生。怎样才能达到我想要的效果?

注意:我想这样做的原因是因为我在 github 上保留了许多脚本,例如 this one,并且我通过这样做来运行它们

curl https://gist.github.com/drew-gross/5706361/raw/update_settings_and_dotfiles.sh | sh

【问题讨论】:

  • 当你运行 echo something |sh 时,生成的 sh 的标准输入已经被重定向。 & sh 调用的read 也将使用相同的重定向stdin

标签: bash shell curl pipe


【解决方案1】:

将脚本传送到 shell 意味着 shell 不是交互式的。尝试将其采购到当前的 shell 中:

. <(echo "read -p test")
. <(curl "$url")

【讨论】:

  • 这会导致语法错误:sh: line 3: syntax error near unexpected token '('sh: line 3: '. &lt;(read -p "Is iTerm2 running? You should quit it!")'
  • 另外,. &lt;(read -p foo) 将尝试在当前 shell 中执行您的 response。将进程替换视为填充了包含脚本的输出的文件。在这种情况下,您正在尝试 source 文件的内容,因此它必须是有效的 shell 命令。
猜你喜欢
  • 2017-01-15
  • 2012-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多