LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Bashism in /etc/rc.d/rc.S (https://www.linuxquestions.org/questions/slackware-14/bashism-in-etc-rc-d-rc-s-4175507325/)

tronayne 06-09-2014 10:49 AM

Quote:

Originally Posted by genss (Post 5184536)
y, arrays are a bash thing

Only in the interests of providing a little information... From at least 1989 KornShell has provided arrays.

Morris L. Bolsky, David G. Kornm, The KornShell Command and Programming Language (Englewood Cliffs, NJ: Prentice Hall, 1989, IDBN 0-13-516972-0), Copyright 1989 AT&T Bell Laboratories.
  • Pg. 61 Arrays
  • Pg. 129 Arithmetic Expressions
  • Pg. 170 Arrays
Strangely, the BASH assignments and manipulation of arrays look, well, pretty much identical to KSH.

bimboleum 06-09-2014 11:52 AM

sh, bash, ksh and other contraversies
 
Hi,
I have been around for more years than I care to think about so my opinions may not be worth much ... ravings of an old fart ... BUT:-

I think it is good practice (when considering shell scripts) that the shebang line reflects the nature of the script so if it uses so-called "bashisms" then use #!/bin/bash, even though you may consider it unnecessary because sh is linked to bash.

For those who indulge in AIX, you will notice that although it uses the Korn shell for it's init scripts, /bin/ksh is the old pre-93 ksh (the ksh that shipped with the original AIX) and post-93 ksh is included as ksh93 ... I hope this is accurate .. it has been a while since I used an AIX system.

I use ksh as my login shell .. have done this from 1989 onward .. and in order to use ksh when I su to "root", I have a specific username (kroot) which is uid 0 with /bin/ksh as it's login shell. This leaves username "root" as whatever is the specified on the system I am using, specifically so that init scripts run as designed (not just as coded!).

What are these ravings all about, you may ask ... well, getting all hot and bothered over which shell does what and how much is not worth it ... they all have their advantages and disadvantages so "horses for courses".

On the other hand, don't get me started on "csh" :-)

As always, YMMV

cheers
pete

pete hilton
saruman@ruvolo-hilton.org

Didier Spaier 06-09-2014 12:19 PM

Quote:

Originally Posted by jtsn (Post 5185109)
Which is a no-op on the Slackware default install, but should make things more robust, because it removes an implicit assumption (sh = bash) and the reliance on a symlink. If you ask me, I'm not against your proposal.

Yes, but... Making that change now could break some shell scripts (be they included in Slackware or written by users), as then bash's behavior, not being called as sh any more, could change. I'm still a beginner in shell scripting, especially in bashing (?!) so I can't give examples, but I assume that our BDFL is not ready to take that risk.

genss 06-09-2014 12:24 PM

Quote:

Originally Posted by tronayne (Post 5185163)
Only in the interests of providing a little information... From at least 1989 KornShell has provided arrays.

Morris L. Bolsky, David G. Kornm, The KornShell Command and Programming Language (Englewood Cliffs, NJ: Prentice Hall, 1989, IDBN 0-13-516972-0), Copyright 1989 AT&T Bell Laboratories.
  • Pg. 61 Arrays
  • Pg. 129 Arithmetic Expressions
  • Pg. 170 Arrays
Strangely, the BASH assignments and manipulation of arrays look, well, pretty much identical to KSH.

interesting, thx

my experience is from replacing bash with ash, for fun
guess assuming arrays are bash specific was false
oh well, you learn something every day

tronayne 06-09-2014 01:40 PM

Quote:

Originally Posted by bimboleum (Post 5185192)
I have been around for more years than I care to think about so my opinions may not be worth much ... ravings of an old fart ...

As a fellow old fart...
Quote:

Originally Posted by bimboleum (Post 5185192)
I think it is good practice (when considering shell scripts) that the shebang line reflects the nature of the script so if it uses so-called "bashisms" then use #!/bin/bash, even though you may consider it unnecessary because sh is linked to bash.

Yup, shebang every shell program (lordy, I hate the word "script" for a shell program).
Quote:

Originally Posted by bimboleum (Post 5185192)
I use ksh as my login shell .. have done this from 1989 onward .. and in order to use ksh when I su to "root", I have a specific username (kroot) which is uid 0 with /bin/ksh as it's login shell. This leaves username "root" as whatever is the specified on the system I am using, specifically so that init scripts run as designed (not just as coded!).

Actually, the name you log in with does not matter once past the log in sequence; all that matters is the UID (and GID, too). If you have a separate account such as kroot with a UID and GID of zero, well, that's root by any other name.

The shell specified in /etc/passwd is the shell program you get when you work on the console or open a terminal, be that sh, bash, ksh, whatever else tickles your fancy. If you're executing programs as UID 0, you're going to be the god of the machine; if you execute them as you, well, you're going to be you (and won't be able to cause much damage, eh?).

Place I worked for, oh, about 12 years (a Sun farm) insisted that all users had to use C-Shell (which was written at Berkeley (IIRC) when all of 'em were dropping acid and smoking weed: how else would they have come up with that mess! :rolleyes: Because I was the only non IT guy with a Sun work station, I ran my own stuff my own way (and insisted that my log in shell be KSH on every other system). Of course non of the shell programs were written in C-Shell (thankfully), we wrote all of 'em in Bourne or Korn and things worked (and are still working I've been told) just fine, thank you very much (been retired about five years).

My complaint with BASH is simple: it violates the founding principles of Unix (and, thus, Linux) as postulated by Doug McIlory (see below for that). Bourne and Korn have not changed over the years (well, Korn a tiny little bit from '89 to '93 plus a twiddle here or there, Boune not at all since like forever). BASH? They keep screwing with it, adding more and more and still more "functionality" and bells and whistles, right down the rosy path to incompatible older shell programs and broken systems. I suppose it is a good feature to have BASH behave itself with the #!/bin/sh; be an awful mess if it didn't.

You know that psychology thing? Glass half full or empty? Engineer: neither; the glass is too big (to do what it needs to do).

I still write pretty much everything in C. I learned C++ (and learned, right quick, that I didn't really care for it all that much and don't really ever use it unless forced to). I will continue to write shell programs in KornShell simply because I have not found anything else worth a damn.

I do so love being an old fart.

jtsn 06-09-2014 01:43 PM

Quote:

Originally Posted by Didier Spaier (Post 5185206)
Yes, but... Making that change now could break some shell scripts (be they included in Slackware or written by users)

The change of the Shebang of rc.S would break other shell scripts? How? Please explain.

Didier Spaier 06-09-2014 02:06 PM

Quote:

Originally Posted by jtsn (Post 5185243)
The change of the Shebang of rc.S would break other shell scripts? How? Please explain.

Already quoted from bash's man page by Stuart:
Code:

      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 don't know exactly how bash's behavior differs upon the name with which it is invoked, but am assuming that theses difference could result in a script also behaving differently -- possibly not the way it was intended to. Reading you response I realize that I probably should have stated this remark as a question.

PS Re-reading your response I see that I didn't answer your question. In fact I was thinking of the consequences of deleting the symlink and changing the shebang if need be for *all* scripts. My bad excuse being that English is a second language for me ;) Of course changing the shebang of only rc.S won't change the behavior of another script.

ReaperX7 06-09-2014 02:14 PM

Actually, Bash follows the UNIX philosophy. While it's functionality has expanded to incorporate syntax and subroutines of other shells to be more comprehensive, it is still a shell and only still a shell.

dederon 06-09-2014 02:18 PM

deleted.

Didier Spaier 06-09-2014 02:19 PM

Quote:

Originally Posted by ReaperX7 (Post 5185253)
Actually, Bash follows the UNIX philosophy. While it's functionality has expanded to incorporate syntax and subroutines of other shells to be more comprehensive, it is still a shell and only still a shell.

Did you post in the right thread? I ask because the link between you statement and the topic escapes me.

drmozes 06-09-2014 02:20 PM

Quote:

Originally Posted by Didier Spaier (Post 5185251)
...Of course changing the shebang of only rc.S won't change the behavior of another script.

I don't think it'd change the behaviour of rc.S either. I've changed many scripts over the years from #!/bin/sh to #!/bin/bash on Linux (where sh is symlinked to bash) and they all continued to work as they did previously.

ReaperX7 06-09-2014 02:24 PM

Quote:

Originally Posted by Didier Spaier (Post 5185256)
Did you post in the right thread? I ask because the link between you statement and the topic escapes me.

Sorry if you can't follow the topic, and I wasn't talking to you...

dederon 06-09-2014 02:29 PM

Quote:

Originally Posted by drmozes (Post 5185257)
I don't think it'd change the behaviour of rc.S either. I've changed many scripts over the years from #!/bin/sh to #!/bin/bash on Linux (where sh is symlinked to bash) and they all continued to work as they did previously.

that's interesting. i too changed the shebang of rc.S to /bin/bash and my system now boots with /bin/sh linked to /bin/mksh. can you name some other scripts which are affected?

eloi 06-10-2014 05:48 AM

Quote:

Originally Posted by dederon (Post 5185264)
that's interesting. i too changed the shebang of rc.S to /bin/bash and my system now boots with /bin/sh linked to /bin/mksh. can you name some other scripts which are affected?

That's the function of the shebang, in this case it calls /bin/bash to execute the code so where /bin/sh links doesn't care anymore.

For the same reason the default shell the installer chooses for user root (in /etc/passwd) is not necessary what the system uses for booting. In any case the shebang tells you the interpreter used. OpenBSD uses its own version of ksh. FreeBSD uses csh for user root but the rc scripts call /bin/sh. I don't know how POSIX are the init scripts on both systems.

Personally I'd avoid bashism in Linux init scripts as much as possible.

Perhaps I'm telling you what you already know.


TEXT ADDED: OK, now I realize what you meant. You mentioned your system boot changing rc.S shebang to /bin/bash to check if other scripts could contain bashism. Sorry for the noise. :)


All times are GMT -5. The time now is 11:04 AM.