2013-03-25 124 views
2

我写了一个bash脚本,应该可以从网上安装。它应该在运行时从用户那里获得输入。 以下是我如何做到的,但它直接终止应用程序而不提示用户输入信息。运行bash脚本卷曲从网络

curl www.test.com/script.sh | bash 

我在某处读到stdin是通过bash连接的,这就是为什么它不会提示任何东西。

任何帮助将是伟大的。

谢谢你们

回答

6

使用process substitution

bash <(curl www.test.com/script.sh) 
+0

该死的,这是整洁。 – Faiz 2013-03-25 00:46:20

0

尝试

bash -c '`curl www.test.com/script.sh`' 

虽然这会出现问题,如果脚本中有单引号。

如果做不到这一点,做的两个步骤:

curl -o /tmp/script.sh www.test.com/script.sh 
bash /tmp/script.sh 

您可以保存脚本您想要的位置,并为更好的安全性等,你可能想使用tmpfile或东西,但运行脚本直客无论如何,网络听起来不像高安全性。

+0

''bash的“'卷曲www.test.com/script。即使没有单引号,sh''''也不起作用。 – pynexj 2013-03-25 01:41:01

+0

糟糕,我忘了'-c'标志。更新。 – lxop 2013-03-27 18:55:37

0

你可以尝试:

bash -c "$(curl -s www.test.com/script.sh)" 

从bash的手册页,

-c string If the -c option is present, then commands are read from string. 
      If there are arguments after the string, they are 
      assigned to the positional parameters, starting with $0. 
+0

这只适用于短于系统最大允许命令行的脚本。 POSIX只保证这个数字大于4096,所以如果你的脚本比较长,这是不可移植的。 – 2013-03-25 00:46:35