ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 3,058
Rep:
#!/bin/sh is probably the best way to go, at least when bash is symlinked to /bin/sh and is called as that it will run in posix mode and disable any bash specific functions.
Make sure they run on ash/dash, and then you can use the '#!/bin/sh', if they don't run because they need bash features then use '#!/bin/bash'. I would use: http://sourceforge.net/projects/checkbaskisms/
with '-p' and maybe '-x' to ensure POSIX compliance.
Last edited by metaschima; 11-23-2014 at 06:44 PM.
From the shells I've tested, 'dash' was the most minimalistic (or most strict if you wish), (an example: it doesn't accept trap '' SIGHUP only trap '' HUP)
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,786
Rep:
@SAbhi You are missing the fact there is almost never a native /bin/sh under Linux. On all mainstream distributions, it is a link to a Bourne shell compatible implementation, commonly bash or dash, less frequently zsh or busybox.
Dash doesn't support array variables and probably never will (unless the POSIX standard decide to add this feature).
I am probably going to cop a flogging for this, but are there really that many distributions that do not contain a copy of bash?
I am aware that it may not necessarily be the system default, but I did not think this implied it was not available at all.
Looking at some main stream distributions like, Mint, Ubuntu, Debian, openSuse, Slackware, I was not able to find any that indicated bash was not included.
I am not saying that posix standards are not the way to go, however, I find the argument to steer away from bash on most modern distributions to not necessarily
be a good argument either.
Just my 2 cents of course
What I can say I have noted as a good practice of late, is that rather than setting the shebang directly is that you let env find it for you.
As an exmple:
As has been shown by recent shellshock bug, relying on a big piece of software when you don't have to may bite you in the ass. Also, there are some distributions that do not contain a copy of bash, for example all those based on busybox.
@SAbhi You are missing the fact there is almost never a native /bin/sh under Linux. On all mainstream distributions, it is a link to a Bourne shell compatible implementation, commonly bash or dash, less frequently zsh or busybox.
Dash doesn't support array variables and probably never will (unless the POSIX standard decide to add this feature).
On most of the systems, Yes it is bash and in many but less to former cases a link to DASH.
based on the fact DASH doesn't support arrays but bash does.
Sorry for not being illustrative in my previous post and thanks for correcting me.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.