LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 06-09-2014, 10:49 AM   #46
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065

Quote:
Originally Posted by genss View Post
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.
 
Old 06-09-2014, 11:52 AM   #47
bimboleum
Member
 
Registered: Oct 2009
Posts: 111

Rep: Reputation: 23
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
 
3 members found this post helpful.
Old 06-09-2014, 12:19 PM   #48
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,055

Rep: Reputation: Disabled
Quote:
Originally Posted by jtsn View Post
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.
 
Old 06-09-2014, 12:24 PM   #49
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
Quote:
Originally Posted by tronayne View Post
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
 
Old 06-09-2014, 01:40 PM   #50
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Quote:
Originally Posted by bimboleum View Post
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 View Post
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 View Post
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! 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.
 
2 members found this post helpful.
Old 06-09-2014, 01:43 PM   #51
jtsn
Member
 
Registered: Sep 2011
Posts: 922

Rep: Reputation: 480Reputation: 480Reputation: 480Reputation: 480Reputation: 480
Quote:
Originally Posted by Didier Spaier View Post
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.
 
Old 06-09-2014, 02:06 PM   #52
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,055

Rep: Reputation: Disabled
Quote:
Originally Posted by jtsn View Post
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.

Last edited by Didier Spaier; 06-09-2014 at 02:15 PM. Reason: PS added.
 
Old 06-09-2014, 02:14 PM   #53
ReaperX7
LQ Guru
 
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,558
Blog Entries: 15

Rep: Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097
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.
 
Old 06-09-2014, 02:18 PM   #54
dederon
Member
 
Registered: Oct 2013
Posts: 107

Original Poster
Rep: Reputation: 56
deleted.
 
Old 06-09-2014, 02:19 PM   #55
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,055

Rep: Reputation: Disabled
Quote:
Originally Posted by ReaperX7 View Post
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.
 
3 members found this post helpful.
Old 06-09-2014, 02:20 PM   #56
drmozes
Slackware Contributor
 
Registered: Apr 2008
Distribution: Slackware
Posts: 1,539

Rep: Reputation: 1308Reputation: 1308Reputation: 1308Reputation: 1308Reputation: 1308Reputation: 1308Reputation: 1308Reputation: 1308Reputation: 1308Reputation: 1308
Quote:
Originally Posted by Didier Spaier View Post
...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.
 
Old 06-09-2014, 02:24 PM   #57
ReaperX7
LQ Guru
 
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,558
Blog Entries: 15

Rep: Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097
Quote:
Originally Posted by Didier Spaier View Post
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...

Last edited by ReaperX7; 06-09-2014 at 02:35 PM.
 
Old 06-09-2014, 02:29 PM   #58
dederon
Member
 
Registered: Oct 2013
Posts: 107

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by drmozes View Post
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?
 
Old 06-10-2014, 05:48 AM   #59
eloi
Member
 
Registered: Nov 2010
Posts: 227

Rep: Reputation: 61
Quote:
Originally Posted by dederon View Post
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.

Last edited by eloi; 06-10-2014 at 07:23 AM.
 
  


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
Bashism in rc.udev - anyone uses ash as /bin/sh ? Camarade_Tux Slackware 3 03-02-2008 02:26 PM

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

All times are GMT -5. The time now is 11:52 PM.

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