On Fri, Apr 24, 2015 at 09:47:24AM -0700, Gordon Messmer wrote:
On 04/24/2015 03:57 AM, Pete Geenhuizen wrote:
if you leave it out the script will run in whatever environment it currently is in.
I'm reasonably certain that a script with no shebang will run with /bin/sh. I interpret your statement to mean that if a user is using ksh
"It depends".
On older Unix-type systems which didn't understand #! then the shell itself did the work. At least csh did (sh didn't necessary). If the first character was a # then csh assumed it was a csh script, otherwise it assumed a sh script. That's why a lot of real old scripts began with :
and enters the path to such a script, it would also run in ksh. That would only be true if you "sourced" the script from your shell.
So on CentOS 5 with ksh93 as my shell
% cat x echo ${.sh.version}
Note that it's a simple one liner with no #!
% ./x Version AJM 93t+ 2010-06-21
That's ksh output!
Let's change my shell to "bash" instead % bash bash-3.2$ ./x ./x: line 1: ${.sh.version}: bad substitution
So now it's bash that's trying to interpret it!
So "it depends" is still true :-)
Basically, without #! there (which allows it to be exec'd) the shell determines how the file is interpreted.