开发者

Difference between piping a file to sh and calling a shell file

开发者_运维知识库

This is what was trying to do:

$ wget -qO- www.example.com/script.sh | sh

which quietly downloads the script and prints it to stdout which is then piped to sh. This unfortunately doesn't quite work, failing to wait for user input at various points, aswell as a few syntax errors.

This is what actually works:

$ wget -qOscript www.example.com/script.sh && chmod +x ./script && ./script

But what's the difference?

I'm thinking maybe piping the file doesn't execute the file, but rather executes each line individually, but I'm new to this kind of thing so I don't know.


When you pipe to sh , stdin of that shell/script will be the pipe. Thus the script cannot take e.g. user input from the console. When you run the script normally, stdin is the console - where you can enter input.


You might try telling the shell to be interactive:

$ wget -qO- www.example.com/script.sh | sh -i


I had the same issue, and after tinkering and googling this is what worked for me.

wget -O - www.example.com/script.sh | sh
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜