#! is an human readable instance of a magic number consisting of the byte string
0x23 0x21, which is used by the
exec() family of functions to determine whether the file to be executed is a script or a binary. When the shebang is present,
exec() will run the executable specified after the shebang instead.
Note that this means that if you invoke a script by specifying the interpreter on the command line, as is done in both cases given in the question,
exec() will execute the interpreter specified on the command line, it won't even look at the script.
So, as others have noted, if you want
exec() to invoke the interpreter specified on the shebang line, the script must have the executable bit set and invoked as
The behaviour is easy to demonstrate with the following script:
ksh to be the interpreter.
$$ holds the PID of the current process.
/proc/pid/exe is a symlink to the executable of the process (at least on Linux, I'm not familiar with AIX so I don't know the equivalent there).
readlink will output the value of the symbolic link.
Note: I'm demonstrating this on Ubuntu, where the default shell
/bin/sh is a symlink to dash i.e.
/bin/ksh is a symlink to
/etc/alternatives/ksh, which in turn is a symlink to
$ chmod +x getshell.sh
$ bash getshell.sh
$ sh getshell.sh