4

What's the difference between

sh myscript

and

sh < myscript

I played around and they seem to have the same effect. Are they equivalent?

  • They aren't the same. The first will open the file along w/ any cmd line args after it. The 2nd will stream the contents of the file myscript into STDIN of sh. – slm Jan 12 '14 at 21:04
9

They are not. There are some things that will not work. The one thing that comes to mind is:

sh myscript -flag1 -value=3

is not possible with sh < myscript.

With sh < myscript, $0 is set to sh, rather than myscript, so

echo this script is $0

won't work

Also, if your script reads input, it will not work - you cannot

sh < myscript < myfiletoread

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.