I know is advised to write a shell script in sh so it's portable to all unix/linux systems.
I know that /bin/sh was a symbolic link to /bin/bash (in rhel) and /bin/sh is a symbolic link to /bin/dash (ubuntu and debian).
How can I execute a script with old sh, not bash or dash?
man bash says:
If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well.
But since there is no binary executable for sh in the system (?) this must be an internal behaviour of bash.
Shell boy: Do not try and bend the shell. That's impossible. Instead only try to realize the truth. Kibou: What truth? Shell boy: There is no shell. Kibou: There is no shell? Shell boy: Then you'll see that it is not the shell that bends, it is only yourself.
I know is advised to write a shell script in sh so it's portable to all unix/linux systems.
If you need to write a portable script, you have to stick with a POSIX compliant shell and also only use POSIX compliant utilities. You should also restrict your syntax and options to the one decribed in the POSIX documentation. Despite a common confusion due to the fact they both share the same name (sh), the POSIX shell is not the traditional legacy Bourne shell but was created from the Korn shell.
Quote:
I know that /bin/sh was a symbolic link to /bin/bash (in rhel) and /bin/sh is a symbolic link to /bin/dash (ubuntu and debian).
How can I execute a script with old sh, not bash or dash?
You probably don't need to. Just use dash or bash in POSIX mode.
Should you really want for some reason to run the legacy bourne shell, you can get it here The Heirloom Bourne Shell
If you need to write a portable script, you have to stick with a POSIX compliant shell and also only use POSIX compliant utilities. You should also restrict your syntax and options to the one decribed in the POSIX documentation. Despite a common confusion due to the fact they both share the same name (sh), the POSIX shell is not the traditional legacy Bourne shell but was created from the Korn shell.
You probably don't need to. Just use dash or bash in POSIX mode.
Should you really want for some reason to run the legacy bourne shell, you can get it here The Heirloom Bourne Shell
So if my shebang is #!/bin/sh but in both systems /bin/sh -> /bin/somewherelese (bash or dash), how do I run it in POSIX mode?
mmm.. according to man bash, if I call a script with:
it will behave the same way as well.
So this means that even there is no /bin/sh executable, the way to execute the bourne shell is through an internal behaviour of bash (--posix suffix) or calling the script like (sh myscript.sh).