Re: [opensuse-factory] why are raw scripts forced into /bin/sh instead of user's shell (a Suse patch to bash)
On Friday 01 March 2013, Carlos E. R. wrote:
El 2013-02-27 a las 22:52 -0600, Larry Finger escribió:
On 02/27/2013 09:59 PM, Linda Walsh wrote:
Why do you think this is SUSE only. Every distro has a default shell, which is what you get when you do not specify the shell to use.
/bin/sh is a link to a shell. Linda, find out which it is in your system.
And note that if you invoke /bin/bash by the /bin/sh link then some bashisms are disabled. To give an example ... rudi@tenfore:~> ls -l /bin/sh lrwxrwxrwx 1 root root 4 2012-11-13 23:17 /bin/sh -> bash rudi@tenfore:~> bash -c ". .bashrc" rudi@tenfore:~> sh -c ". .bashrc" sh: line 0: .: .bashrc: file not found rudi@tenfore:~> cu, Rudi -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Ruediger Meier wrote:
On Friday 01 March 2013, Carlos E. R. wrote:
/bin/sh is a link to a shell. Linda, find out which it is in your system.
And note that if you invoke /bin/bash by the /bin/sh link then some bashisms are disabled.
ll /bin/sh lrwxrwxrwx 1 9 Jan 23 02:03 /bin/sh -> /bin/bash
But the problem is what Ruediger Meier wrote -- if you don't invoke the user's shell the way it is in their /etc/passwd (or in their SHELL -- usually the same), then you are changing the user's default shell with which such scripts are executed. I stumbled on to this because I typed a command -- re-edited it a few times. It became multi-line, started to press 'v' in edit mode to bring up the visual editor (vim/gvim in my case). Got tired of it flipping back and forth -- wanted the editor to stay up while I continued executing it and refining it. So saved it to /tmp/xx and used gvim on that -- then my script no longer worked. *IF* I put in #!/bin/bash at the beginning, then the correct shell is used, but by default, it should use the same shell as what the user is running under when they type the name of the shell script. It would be like developing a shell script, then when I put it in a file and execute it (w/o any header line), someone chose to run a #/bin/python on my script instead of the shell I was using. How can that make any sense? -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Quoting Linda Walsh
But the problem is what Ruediger Meier wrote -- if you don't invoke the user's shell the way it is in their /etc/passwd (or in their SHELL -- usually the same), then you are changing the user's default shell with which such scripts are executed.
[...]
*IF* I put in #!/bin/bash at the beginning, then the correct shell is used, but by default, it should use the same shell as what the user is running under when they type the name of the shell script.
It would be like developing a shell script, then when I put it in a file and execute it (w/o any header line), someone chose to run a #/bin/python on my script instead of the shell I was using.
Whereas I sort of understand your point (I hope), I also have to say that 'not specifying' the she-bang would leave you in a much worse situation, as a user NOT running bash (but maybe ash, zsh, csh), would execute your script and then fall flat on his nose... because the script requires bash to execute (due to bashism). Would be as bad as writing python code and hoping that bash knows what to do with it when not specifying the interpreter. Dominique -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Dominique Leuenberger a.k.a. Dimstar wrote:
Whereas I sort of understand your point (I hope), I also have to say that 'not specifying' the she-bang would leave you in a much worse situation, as a user NOT running bash (but maybe ash, zsh, csh), would execute your script and then fall flat on his nose... because the script requires bash to execute (due to bashism).
I whole heartedly agree -- if it was anything other than a personal, script in /tmp, I would add the #! line, but it was something that was a 1-liner that grew. But a script with no header, -- if I'm in a script-interpreter shell like bash and I know it normally executes such in itself -- I think it's perfectly reasonable for me to expect personal use to use the normal default of the interpreter I'm using. It breaks BASH compatibility. (Note, POSIX compatibility doesn't apply here, as I didn't ask for a POSIX compatible shell). -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
On Fri, 1 Mar 2013 01:06, Ruediger Meier
On Friday 01 March 2013, Carlos E. R. wrote:
El 2013-02-27 a las 22:52 -0600, Larry Finger escribió:
On 02/27/2013 09:59 PM, Linda Walsh wrote:
Why do you think this is SUSE only. Every distro has a default shell, which is what you get when you do not specify the shell to use.
/bin/sh is a link to a shell. Linda, find out which it is in your system.
And note that if you invoke /bin/bash by the /bin/sh link then some bashisms are disabled.
To give an example ...
rudi@tenfore:~> ls -l /bin/sh lrwxrwxrwx 1 root root 4 2012-11-13 23:17 /bin/sh -> bash rudi@tenfore:~> bash -c ". .bashrc" rudi@tenfore:~> sh -c ". .bashrc" sh: line 0: .: .bashrc: file not found rudi@tenfore:~>
Yep! But the most perfide thing is: some of the bashisms still work. If a script still works with "/bin/sh -> bash", do the test again, with "/bin/sh -> ash", as not even zsh, nor (t)csh are disabling all the "extras" when called as /bin/sh . Happy debugging! (I've killed more than 2500 hours on such sh.t) - Yamaban
Yamaban
If a script still works with "/bin/sh -> bash", do the test again, with "/bin/sh -> ash", as not even zsh, nor (t)csh are disabling all the "extras" when called as /bin/sh .
If you link /bin/sh to (t)csh, you will definitely break your system as csh is not Shell compatible at all. The other shells are more or less compatible.... and it is good practice to write scripts to be compatible to the Bourne Shell to avoid to depend on other shells specifics. Jörg -- EMail:joerg@schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin js@cs.tu-berlin.de (uni) joerg.schilling@fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/ URL: http://cdrecord.berlios.de/private/ ftp://ftp.berlios.de/pub/schily -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Joerg Schilling wrote:
Yamaban
wrote: If a script still works with "/bin/sh -> bash", do the test again, with "/bin/sh -> ash", as not even zsh, nor (t)csh are disabling all the "extras" when called as /bin/sh .
If you link /bin/sh to (t)csh, you will definitely break your system as csh is not Shell compatible at all.
The other shells are more or less compatible.... and it is good practice to write scripts to be compatible to the Bourne Shell to avoid to depend on other shells specifics.
So you are saying people should avoid Perl, Java and Python? They are all scripting languages. Just like Bash is a scripting language. however, linking /bin/sh to "/bin/dash" wouldn't be unreasonable as it purports to be POSIX compliant (unlike the Bourne Shell, if you could find a copy of that anywhere, which is not). -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
participants (5)
-
Dominique Leuenberger a.k.a. Dimstar
-
Joerg Schilling
-
Linda Walsh
-
Ruediger Meier
-
Yamaban