From: superpollo on
Janis Papanagnou ha scritto:
....
>>>>> While the proposed code is nothing I would suggest to use
>>>> can you explain why please?
>>>
>>> Code that has the following properties that you use I consider suspect
>>> and unreliable;
>>>
>>> 1. misleading shebang unnecessarily set to bash
>>
>> is #!/usr/bin/bash better? what should i put there instead?
>
> If you're using just standard shell features without relying on any
> bash'isms I'd suggest specify just that; standard sh.
>
> Especially if the OP hasn't asked for a specific shell it's better
> to not assume that he has a bash on his system, and to not give the
> impression that bash would be required to execute your code.

unfortunately on my system:

~/superpollo$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2009-09-10 12:22 /bin/sh -> bash

but i have dash. do you suggest to use it as a standard sh?

apart the faq, is there some good printed or online resource to get
acquainted with the standard shell and relative idioms?

tia

bye
From: Seebs on
On 2010-06-07, superpollo <utente(a)esempio.net> wrote:
> Janis Papanagnou ha scritto:
>> Especially if the OP hasn't asked for a specific shell it's better
>> to not assume that he has a bash on his system, and to not give the
>> impression that bash would be required to execute your code.

> unfortunately on my system:

> ~/superpollo$ ls -l /bin/sh
> lrwxrwxrwx 1 root root 4 2009-09-10 12:22 /bin/sh -> bash

This is 100% totally irrelevant to what you were just told.

The point is, don't explicitly ask for bash in the #! unless you
ACTUALLY NEED IT. Which you almost never do.

If you specify "#!/bin/sh", and write your script cleanly, it WON'T
MATTER whether it's dash or bash or ash or ksh. It'll work anyway,
because you wrote standard code and requested the standard path to
the standard shell.

It doesn't matter that, on your system, it happens to be the same
program as /bin/bash (note that it will not behave the same, though,
because bash notices the name you invoke it with), and on another
system, it might be the same program as /bin/dash. As long as your
code follows the standard, "#!/bin/sh" will work.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Janis Papanagnou on
superpollo wrote:
> Janis Papanagnou ha scritto:
> ...
>>>>>> While the proposed code is nothing I would suggest to use
>>>>> can you explain why please?
>>>>
>>>> Code that has the following properties that you use I consider suspect
>>>> and unreliable;
>>>>
>>>> 1. misleading shebang unnecessarily set to bash
>>>
>>> is #!/usr/bin/bash better? what should i put there instead?
>>
>> If you're using just standard shell features without relying on any
>> bash'isms I'd suggest specify just that; standard sh.
>>
>> Especially if the OP hasn't asked for a specific shell it's better
>> to not assume that he has a bash on his system, and to not give the
>> impression that bash would be required to execute your code.
>
> unfortunately on my system:
>
> ~/superpollo$ ls -l /bin/sh
> lrwxrwxrwx 1 root root 4 2009-09-10 12:22 /bin/sh -> bash
>
> but i have dash. do you suggest to use it as a standard sh?

No. (Seebs has answered that point in detail.)

>
> apart the faq, is there some good printed or online resource to get
> acquainted with the standard shell and relative idioms?

Well, there's the SUS standard that defines it, but it's no tutorial,
so it's nothing I would suggest in this case.

Chris Johnson seems to prefer using bash, and AFAICT is very focussed
on standard shell, so his book might be somthing to consider. I don't
know his book, though, or rather, I've only seen a couple pages.

Personally I prefer to use Kornshell for scripting. The book "The new
Kornshell" from Bolsky and Korn has at least an appendix "Features of
ksh not in POSIX shell", so you'd at least know what is ksh specific.

Besides those hints I can just suggest to google for online tutorials;
that way you *may* find something that's worth to read. I haven't done
that so I cannot help further.

Janis

>
> tia
>
> bye
From: superpollo on
Seebs ha scritto:
> On 2010-06-07, superpollo <utente(a)esempio.net> wrote:
>> Janis Papanagnou ha scritto:
>>> Especially if the OP hasn't asked for a specific shell it's better
>>> to not assume that he has a bash on his system, and to not give the
>>> impression that bash would be required to execute your code.
>
>> unfortunately on my system:
>
>> ~/superpollo$ ls -l /bin/sh
>> lrwxrwxrwx 1 root root 4 2009-09-10 12:22 /bin/sh -> bash
>
> This is 100% totally irrelevant to what you were just told.
>
> The point is, don't explicitly ask for bash in the #! unless you
> ACTUALLY NEED IT. Which you almost never do.
>
> If you specify "#!/bin/sh", and write your script cleanly, it WON'T
> MATTER

that's why i asked him for some tutorial. he answered, but told me no
cigar: no online or printed advice for clean/standard shell programming.

bye



From: Seebs on
On 2010-06-08, superpollo <utente(a)esempio.net> wrote:
> that's why i asked him for some tutorial. he answered, but told me no
> cigar: no online or printed advice for clean/standard shell programming.

Of course there is. There's tons of it. The autoconf manual has a great
deal of information on standard shell programming, and my book talks a
fair bit about shell programming. ("Beginning Portable Shell Scripting",
APress)

But you're still missing the point. Nothing anyone said here had to do
with you needing to know something about standard shell programming you
don't know now. It was just a suggestion that you write "#!/bin/sh"
regardless of whether sh is bash or dash or whatever, because it's cleaner
and less likely to cause trouble on other systems unless you specifically
*know* that you are depending on non-standard features.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!