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?

1
  • 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. Commented Jan 12, 2014 at 21:04

1 Answer 1

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
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.