SlackwareThis Forum is for the discussion of Slackware Linux.
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.
In theory, dash should be faster than bash. So I was wondering if you should link sh to dash (instead of bash). Can this cause problems with existing scripts under Slackware?
I also noticed that /bin/sh is a link to bash, but bash is started in a certain mode: The prompt is sh-5.1 instead of bash-5.1. So is this already a script-optimized version of bash? If so, does it even make sense to link sh to dash or is this optimized version of bash just as fast?
My user shell is zsh, I think using dash as a user shell is insane. Its main purpose is to not have to worry about all the features that a convenient user shell should have. It's optimized for running scripts and being a system shell (it's the default system shell on debian). But what you said is true, there could be trouble changing the system shell. That's the reason I asked this question.
Whether you have problems or not changing /bin/sh to dash will highly depend on the quality of the scripts of the system.
You can check at current ChangeLog.txt and see:
Code:
Sat Apr 24 18:55:05 UTC 2021
a/pkgtools-15.0-noarch-40.txz: Rebuilt.
Change several script shebangs to #!/bin/bash. Thanks to mumahendras3.
... And also:
Code:
Fri Apr 23 19:13:09 UTC 2021
a/sysvinit-scripts-15.0-noarch-2.txz: Rebuilt.
Use #!/bin/bash for these scripts so that bashisms don't cause script issues
if /bin/sh is some other shell. Thanks to mumahendras3.
rc.S: Use GazL's proposals for detecting/mounting /proc and /sys.
As you can see in those logs, some scripts of the system have been changed from #!/bin/sh to #!/bin/bash. Why? Because such scripts were using code that is not POSIX compliant, so it makes sense to use bash since bash-isms are being used there.
If there is a script that is using non POSIX compliant functionality and if the script itself is having #!/bin/sh in the first line and /bin/sh is linked to an only POSIX compliant shell then the script may not work at times or just entirely not work.
As I said earlier, whether you have problems or not changing /bin/sh to dash will depend in that the scripts that are not POSIX compliant are using a proper shebang link to the shell that they have been created for.
I do believe the reason the prompt shows up as sh-5.1 instead of bash-5.1 is because bash checks to see how it was started ($0) and it sees /bin/sh, so it adjusts the prompt accordingly. The man page says
Quote:
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.
I changed the /bin/sh link to dash the other day after mumahendras3 had got some fixes in the rc scripts, nothing has catastrophically broke so far. The output of the rc.cups script was a bit malformed, but I just changed the shebang in that to bash as well. I think with the recent changes to pkgtools shebang that might fix any "serious" issues that might arise, but this is pure speculation.
Prior to this I was looking into POSIXify some of the rc scripts and pkgtools scripts, but I didn't put too much effort into it as I wasn't sure if the changes would even be accepted. Some of the rc scripts would take a lot of effort to do so, probably with very little or no gain in performance, but would have a lot more complexity (eg rc.inet1 makes heavy use of arrays and recreating with simulated arrays would be complex and not worth it as a whole.)
Some tools you can use if you are really curious is checkbashisms and shellcheck. These can point out if you have a script that claims to be POSIX shell script but it uses some bashisms.
Do note that dash has some additional extensions (eg echo accepts some flags like -n) beyond "strict" POSIX compliance.
But changing the /bin/sh link to dash should be done with caution.
I'm a firm believer in experimentation. That being said my view is also that this type of thing is why extremely user friendly virtualization apps exist. I'd use Virtual Box for this one as you can easily snapshot the image before you do it.
Last edited by jmgibson1981; 04-24-2021 at 08:00 PM.
FWIW I recently found myself in the unfortunate position of trying to write a simple shell script on an Ubuntu system. It's a simple script using SH/BASH compatible syntax but it failed hard when I set the starting line to #!/bin/sh.
On Ubuntu, sh is a link to dash and there are some syntax differences. I changed the line to #!/bin/bash and never looked back. If dash is faster it's probably because it skimps on some features and ultimately breaks compatibility with BASH scripts. Not worth it in my opinion.
I have no systemd, but I hear it does not boot faster any more, became too bloated. The advantage over OpenRC with parallel boot enabled was marginal anyway. Faster boot is just one of those salesman tales.
FWIW I recently found myself in the unfortunate position of trying to write a simple shell script on an Ubuntu system. It's a simple script using SH/BASH compatible syntax but it failed hard when I set the starting line to #!/bin/sh.
No if dash can't run it it is not a POSIX compliant shell script. You wrote a bash script not a shell/sh script. You should only use #!/bin/sh if your script is POSIX compliant.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.