Is it safe and sensible to link sh to dash?
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? |
I would never mess with system shell, it is not worth the potential trouble, IMHO. User shell is another story, whatever suits you best.
|
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 Code:
Fri Apr 23 19:13:09 UTC 2021 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:
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. |
To add some fun the POSIX specification of the Shell Command Language, in its chapter 2.1 Shell Introduction states:
Quote:
|
No, someone tried something like that many years ago, but I think it was ash. That caused a lot of startup issues.
|
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.
|
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. |
Quote:
|
Quote:
|
Quote:
For everything else, it is just a celestial debate on a Shao-Lin temple. Not meaningful for us, the mortal sinners. |
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.
|
Quote:
|
Quote:
|
All times are GMT -5. The time now is 10:17 AM. |