[Slackbuilds-users] bashisms?

Jim Diamond Jim.Diamond at acadiau.ca
Sat Aug 29 12:16:46 UTC 2015


On Sat, Aug 29, 2015 at 04:16 (-0400), B Watson wrote:

> On 8/28/15, Jim Diamond <Jim.Diamond at acadiau.ca> wrote:

>> and otherwise following
>> good programming practices by explicitly declaring that the shell
>> script must be run by bash if that is, indeed, the case).

> I tried doing that, it got changed back to #!/bin/sh, so I just gave up.
I think changing that was unnecessary and ill-advised (unless the
person who changed it verified there were no bash-isms at all).

> I don't use other shells normally, and haven't memorized the POSIX shell
> spec,
Yeah, that is a job for someone with lots of time on their hands.
> so can't remember (and can't be bothered to forever be looking up)
> what's a bashism and what isn't.  Horrible attitude maybe, but it is
> what it is, so I normally use #!/bin/bash to avoid confusion and
> breakage.

> I suppose if a forked or future Slackware someday has /bin/sh as non-bash,
> it'd be easy enough to sed the shebangs to #!/bin/bash on the entire SBo
> repo.
Well, this is, I believe, something which is also wrong in principle.
I have this fuzzy recollection of some difference in the order of how
parsing is done between bash and POSIX specs.  I can't think of what
it is now, but it was something along the lines of this difference
between bash and zsh:

bash (at least with the options I get when I run it):
$ b='echo a'
$ $b
a

zsh (at least with the options I get when I run it):
$ b='echo a' 
$ $b
zsh: command not found: echo a

In other (very loosely-spoken) words, bash does word-splitting on the
results of variable expansion before parsing the whole line, and zsh
does not.

So it is possible that changing someone's #!/bin/sh to #!/bin/bash
could break the shell script.

Of course, this could all be a moot point.

Cheers.

                                Jim


More information about the SlackBuilds-users mailing list