LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-24-2021, 05:10 PM   #1
M0M0
Member
 
Registered: Sep 2020
Location: Germany
Distribution: Slackware
Posts: 230

Rep: Reputation: 20
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?
 
Old 04-24-2021, 05:17 PM   #2
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
I would never mess with system shell, it is not worth the potential trouble, IMHO. User shell is another story, whatever suits you best.
 
1 members found this post helpful.
Old 04-24-2021, 05:23 PM   #3
M0M0
Member
 
Registered: Sep 2020
Location: Germany
Distribution: Slackware
Posts: 230

Original Poster
Rep: Reputation: 20
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.

Last edited by M0M0; 04-24-2021 at 05:24 PM.
 
Old 04-24-2021, 05:30 PM   #4
slac
Member
 
Registered: May 2019
Posts: 265

Rep: Reputation: Disabled
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.
 
Old 04-24-2021, 05:32 PM   #5
kaott
Member
 
Registered: Mar 2020
Posts: 63

Rep: Reputation: Disabled
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.

Last edited by kaott; 04-24-2021 at 05:39 PM.
 
1 members found this post helpful.
Old 04-24-2021, 05:53 PM   #6
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,065

Rep: Reputation: Disabled
To add some fun the POSIX specification of the Shell Command Language, in its chapter 2.1 Shell Introduction states:
Quote:
If the first line of a file of shell commands starts with the characters "#!", the results are unspecified.
 
Old 04-24-2021, 06:48 PM   #7
jmccue
Member
 
Registered: Nov 2008
Location: US
Distribution: slackware
Posts: 703
Blog Entries: 1

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
No, someone tried something like that many years ago, but I think it was ash. That caused a lot of startup issues.
 
Old 04-24-2021, 07:58 PM   #8
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,150

Rep: Reputation: 393Reputation: 393Reputation: 393Reputation: 393
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.
 
Old 04-24-2021, 08:20 PM   #9
Pithium
Member
 
Registered: Jul 2014
Location: Far side of the Oregon Trail
Distribution: Slackware64 15.0
Posts: 508

Rep: Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586
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.
 
Old 04-24-2021, 08:20 PM   #10
ZhaoLin1457
Senior Member
 
Registered: Jan 2018
Posts: 1,032

Rep: Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238
Quote:
Originally Posted by M0M0 View Post
In theory, dash should be faster than bash.
And even faster is systemd. It's sensible faster. We should move to systemd, according with you?

Last edited by ZhaoLin1457; 04-24-2021 at 08:21 PM.
 
2 members found this post helpful.
Old 04-24-2021, 08:30 PM   #11
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,714

Rep: Reputation: 2734Reputation: 2734Reputation: 2734Reputation: 2734Reputation: 2734Reputation: 2734Reputation: 2734Reputation: 2734Reputation: 2734Reputation: 2734Reputation: 2734
Quote:
Originally Posted by ZhaoLin1457 View Post
And even faster is systemd. It's sensible faster. We should move to systemd, according with you?
Surely you are not suggesting that systemd is a shell or shell replacement? The two factors are very different.
 
Old 04-24-2021, 08:33 PM   #12
ZhaoLin1457
Senior Member
 
Registered: Jan 2018
Posts: 1,032

Rep: Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238
Quote:
Originally Posted by wpeckham View Post
Surely you are not suggesting that systemd is a shell or shell replacement? The two factors are very different.
I see no matter where a faster shell would matter, other than the init stage.

For everything else, it is just a celestial debate on a Shao-Lin temple. Not meaningful for us, the mortal sinners.
 
1 members found this post helpful.
Old 04-24-2021, 08:58 PM   #13
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
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.
 
Old 04-25-2021, 01:22 AM   #14
M0M0
Member
 
Registered: Sep 2020
Location: Germany
Distribution: Slackware
Posts: 230

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by ZhaoLin1457 View Post
I see no matter where a faster shell would matter, other than the init stage.
Well, It matters all the time you run a POSIX compliant shell script..
 
Old 04-25-2021, 01:26 AM   #15
M0M0
Member
 
Registered: Sep 2020
Location: Germany
Distribution: Slackware
Posts: 230

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by Pithium View Post
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.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Expanding the 'Covered Business Method' program: Sensible patent reform ... and why opponents LXer Syndicated Linux News 0 09-25-2013 06:10 PM
LXer: Developers: Give us sane and sensible default system and application settings LXer Syndicated Linux News 5 08-14-2013 12:16 PM
how do I make a sensible list from a directory structure? oskar Linux - General 2 06-25-2008 12:27 PM
A more sensible editor with indent Haraldsh Linux - Software 2 11-12-2004 06:49 AM
Jeremy: You're Not sensible futurist General 20 04-08-2002 06:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration