By deploying the bit to @DigitalRoss, reply :.
Executable script without #! the first line runs /bin/sh - even if you execute it from bash (or tcsh ). This is not shell functionality; it is at the core.
So, when you executed your script, it was executed /bin/sh (which means that on most systems it will not be able to use bash-specific functions), $! expanded to zero (since this shell did not start any background processes), and the first line calls the interactive shell /bin/bash . Then you exit this interactive shell and your script runs the line echo Hello world! and exits, returning you to the original shell.
For example, if you change echo Hello world! on echo $BASH_VERSION , you will find that you are not printing anything - and if you type history from the called interactive bash shell, it will not show anything.
Keith thompson
source share