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/)

ReaperX7 06-07-2014 08:57 PM

I think FreeBSD uses csh.

dederon 06-08-2014 02:18 AM

This is annoying. I've should have chosen another title (like "wrong /bin/sh shebang line in /etc/rc.d/rc.S" or so).

All I wanted to say was:

1. There is Bash code in /etc/rc.d/rc.S.
2. This file has a "/bin/sh" shebang line, which is wrong.
3. The fix is easy - change /bin/sh to /bin/bash.

i am serious about this matter, as rc.S is one of the most importants scripts. I'd really like to read an oppinion from Pat about that, but I think he won't wade through all the "ksh vs. bash" pages.

Didier Spaier 06-08-2014 02:31 AM

Quote:

Originally Posted by dederon (Post 5184432)
1. There is Bash code in /etc/rc.d/rc.S.
2. This file has a "/bin/sh" shebang line, which is wrong.
3. The fix is easy - change /bin/sh to /bin/bash.

Code:

~$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 déc.  23  2012 /bin/sh -> bash
~$

Isn't that enough?

ruario 06-08-2014 05:00 AM

Quote:

Originally Posted by dederon (Post 5184432)
This is annoying. I've should have chosen another title (like "wrong /bin/sh shebang line in /etc/rc.d/rc.S" or so).

All I wanted to say was:

1. There is Bash code in /etc/rc.d/rc.S.
2. This file has a "/bin/sh" shebang line, which is wrong.
3. The fix is easy - change /bin/sh to /bin/bash.

Sure /etc/rc.d/rc.S should really say /bin/sh but really, in the grand scheme of things it just doesn't matter and if it ain't broke, don't fix it.

tronayne 06-08-2014 06:24 AM

Quote:

Originally Posted by jpollard (Post 5184060)
Why would you switch to the korn shell?

Well, I've been using KornShell for..., um, just about 25 years (in Unix, Solaris and Slackware) with zero problems. During that time, BASH came along, tried it, didn't much like it and it kept "improving" (read: bloat). Too, BASH incorporates a great deal of the functionality (and syntax) of both KornShell and Bourne (along with the C-Shell thrown in for good measure).

User accounts on my systems (and those that I've administered over time) have defaulted to /bin/ksh (users are free to change to BASH if they want, most haven't). Haven't had too many complaints.

Leaving system software (including all start up, shut down, rc's alone) to execute as /bin/sh (which, yeah, is BASH, not actual sh) is no problem; things work if you let them.

There is no reason to remove BASH, leave it there, just don't use it -- just change the account shell in /etc/passwd from /bin/bash to /bin/ksh and life is good. Wouldn't mess with the system accounts (except root which is /bin/ksh on all my systems).

I would note that the above has never resulted in any difficulties whatsoever.

Hope this helps some.

drmozes 06-08-2014 06:59 AM

Quote:

Originally Posted by dederon (Post 5184432)
This is annoying. I've should have chosen another title (like "wrong /bin/sh shebang line in /etc/rc.d/rc.S" or so).

All I wanted to say was:

1. There is Bash code in /etc/rc.d/rc.S.
2. This file has a "/bin/sh" shebang line, which is wrong.
3. The fix is easy - change /bin/sh to /bin/bash.

i am serious about this matter, as rc.S is one of the most importants scripts. I'd really like to read an oppinion from Pat about that, but I think he won't wade through all the "ksh vs. bash" pages.

Bash is designed to be invoked as 'sh' - check the man page:
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.

There are certain pieces of functionality in bash which only work if you switch off POSIX compliance (set +o posix).
Perhaps bash *shouldn't* execute the code you're referring to if it's mimicking the behavior of 'sh' - maybe you should check with the authors of bash?

Gerard Lally 06-08-2014 07:57 AM

Quote:

Originally Posted by 55020 (Post 5184284)
Hey! Calm down!

It can hardly be news to you that loose statements in a book written in 1993 don't really grok Linux, which first saw the light of day in... 1991. The O'Reilly book is not ksh.

Once again, two wildly inaccurate statements. The second edition was heavily revised and appeared in 2002, 11 years after Linux appeared and 2 years after ksh93 was released as open-source in 2000.

I'm not sure what you mean when you say the O'Reilly book is not ksh. I'm half-way through the book and it certainly seems to be all about the official Korn shell, ksh93, to me.

Quote:

FYI I personally consider ksh to be vastly superior to bash in many regards, and that it's highly regrettable that AT&T killed any hope of wide adoption by hanging onto a restrictive licence until long after bash became impossible to dislodge, but hey, apparently I'm an uninformed elitist, so what would I know.
This is a very strange thread. If you ignore the obvious trolls this Slackware forum is invariably informative, with interesting input from people who have years of experience. But in this thread we've had more than a couple of long-established members offering completely ill-informed opinions, if not indeed outright falsehoods. As if that wasn't bad enough, they have sought to impose certain viewpoints on other users, adopting a contemptuous and dismissive tone in the process that I for one have come to expect elsewhere in the Linux world, but not here. A sad day indeed if that elitist, patronising and ill-informed attitude takes root here.

genss 06-08-2014 08:17 AM

Quote:

Originally Posted by dederon (Post 5184054)
eval LUKSARRAY=( $line )

This line, and the following lines

LUKS="${LUKSARRAY[0]}"
DEV="${LUKSARRAY[1]}"
PASS="${LUKSARRAY[2]}"
OPTS="${LUKSARRAY[3]}"

look like bash code to me. Affected is X86_64 current and i686 14.1.

I am not an shell expert, can someone confirm this? Or provide a simple solution? Otherwise I will sot down and write a patch to solve this issue.

heiko

y, arrays are a bash thing

if i read it right something like http://stackoverflow.com/questions/5...tring-variable and a counter
there is maybe a better solution but none comes to mind

there is more bashism in inet scripts and more
also shutdown scripts use "kill" that is the gnu /bin/kill in bash but builtin in ksh so you'd need to change that to /bin/kill or change the flags to be posix so ksh don't fail

allend 06-08-2014 08:38 AM

There is also the issue of future proofing. If smash (the new Super Mega All-in-one shell) came along, then a simple change 'ln -s /bin/smash /bin/sh' would allow the init scripts to continue to function.

55020 06-08-2014 09:13 AM

Quote:

Originally Posted by gezley (Post 5184527)
Once again, two wildly inaccurate statements. The second edition was heavily revised and appeared in 2002, 11 years after Linux appeared and 2 years after ksh93 was released as open-source in 2000.

The CPL is more restrictive than, and incompatible with, the GPL. I didn't say the licence wasn't open source; I said it was restrictive. Even the CPL's progenitor (IBM) has disowned it.

The book's statement that misled you, and at least one more like it, should clearly have been excised from the 2002 revision. They were not. That's what confused you. Please don't keep shooting the messenger; it hurts, actually.

Quote:

Originally Posted by gezley (Post 5184527)
I'm not sure what you mean when you say the O'Reilly book is not ksh.

You've never seen that Magritte painting? The O'Reilly book is not ksh; the O'Reilly book is a book about ksh.

When I criticise one statement in the O'Reilly book, I am not criticising ksh, nor am I trashing the whole of the O'Reilly book, nor am I trashing *you* *personally*.

Quote:

Originally Posted by gezley (Post 5184527)
This is a very strange thread. If you ignore the obvious trolls this Slackware forum is invariably informative, with interesting input from people who have years of experience. But in this thread we've had more than a couple of long-established members offering completely ill-informed opinions, if not indeed outright falsehoods. As if that wasn't bad enough, they have sought to impose certain viewpoints on other users, adopting a contemptuous and dismissive tone in the process that I for one have come to expect elsewhere in the Linux world, but not here. A sad day indeed if that elitist, patronising and ill-informed attitude takes root here.

Wow. Just *wow*. Where did all that come from? <spock> Fascinating </spock>

GazL 06-08-2014 10:05 AM

Quote:

Originally Posted by drmozes (Post 5184503)
Bash is designed to be invoked as 'sh' - check the man page:
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.


And it's broken. When bash is started as 'sh' it enters POSIX mode, and runs /etc/profile followed by $ENV as a proper POSIX shell should do; both ksh and ash do this.

But try this: create yourself a test user with /bin/sh specified as its login shell. When you login from the login prompt on a console, everything works as expected, bash starts in POSIXLY_CORRECT mode and runs the POSIX startup scripts.

Now, try a "su - testuser" instead: bash will start in its normal native mode, not POSIX mode. The reason for this, is that bash looks at argv[0] to see whether it is running as 'sh' or not, but when started by 'su' argv[0] is 'su' and bash has no way of knowing what mode to start in. Its approach is fundamentally flawed.

This is why I was saying above that I have no problem with bash when it's run in its native bash mode, but its not a good choice to use for the POSIX /bin/sh.

So, we have the strange situation on Slackware where a user wanting a POSIX shell can't use /bin/sh as their default shell because it wont work correctly.

I accept that this is only a edge-case that the typical user will remain blissfully ignorant of, but stuff like this gets under my skin.

Didier Spaier 06-08-2014 10:14 AM

Quote:

Originally Posted by GazL (Post 5184574)
So, we have the strange situation on Slackware where a user wanting a POSIX shell can't use /bin/sh as their default shell because it wont work correctly.

The user can just set /bin/ash as default shell then.

But in the other hand if the user doesn't know that invoked as sh bash behaves as a POSIX shell he or she we will invoke it with the --posix option anyway (just kidding :)

drmozes 06-08-2014 12:56 PM

Quote:

Originally Posted by Didier Spaier (Post 5184581)
The user can just set /bin/ash as default shell then.

But in the other hand if the user doesn't know that invoked as sh bash behaves as a POSIX shell he or she we will invoke it with the --posix option anyway (just kidding :)

Most of my scripts begin with #!/bin/sh as a habit from using Solaris at University, but my scripts have for many years tended to use some bash-specific code (some of which requires set +o posix). I'd have moved to invoking 'bash' if it'd have been required.

My personal opinion of the standard 'sh' is that if you ever had the misfortune to have it as your shell on Solaris, one of the first things you did was to find a binary package of 'bash' and compile or install it :-)
I recall one of the first things I had to do with 'sh' was: stty erase <press backspace>
I did like Solaris though.

GazL 06-08-2014 03:37 PM

Ahh yes, the old backspace/del issue. Used to have to muck about with that on AIX too. :) But that's more to do with the terminal and tty layer than the shell. It's only because bash uses readline for its command line input that you don't see the problem in bash, but have the wrong terminal setting and you can still see the escape codes appear in stdin when you hit backspace when running programs that read directly from stdin without readline, even when started under bash.

Code:

gazl@ws1:~$ od -tx1c
I'm gonna press backspace now. ^H
0000000  49  27  6d  20  67  6f  6e  6e  61  20  70  72  65  73  73  20
          I  '  m      g  o  n  n  a      p  r  e  s  s   
0000020  62  61  63  6b  73  70  61  63  65  20  6e  6f  77  2e  20  08
          b  a  c  k  s  p  a  c  e      n  o  w  .      \b
0000040  0a
        \n
0000041

If anything bash is masking the fact that your terminal isn't set up correctly.

"stty erase ^H" can still be used to fix that, but if you get the right settings in your terminal it's not necessary.
I use these Xresources for xterm:
?.vt100.metaSendsEscape: true
?.vt100.backarrowKey: false

jtsn 06-09-2014 09:22 AM

Quote:

Originally Posted by dederon (Post 5184432)
1. There is Bash code in /etc/rc.d/rc.S.
2. This file has a "/bin/sh" shebang line, which is wrong.

Well, "wrong" might not the right term here. Slackware is the oldest surviving Linux distribution and predates most of what "modern" Linux distributions consider "right". Of course nowadays one might think, that /bin/sh should point to a real POSIX shell, so "bashisms" don't go by unnoticed. I agree with that.
Quote:

3. The fix is easy - change /bin/sh to /bin/bash.
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.


All times are GMT -5. The time now is 05:07 AM.