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

Posted by Peter Coulton on Stack Overflow See other posts from Stack Overflow or by Peter Coulton
Published on 2010-04-29T21:24:22Z Indexed on 2010/04/29 21:27 UTC
Read the original article Hit count: 332

Filed under:
|

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 a 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.

© Stack Overflow or respective owner

Related posts about shell

Related posts about pipes