Sundag 17. april 2011 skreiv Mojca Miklavec:
>Alan wrote me about the following issue. I don't know anything about
>bash/sh issues (except that sh is indeed more likely to be present and
>that I had to change many occurencies of /bin/sh to /bin/bash on
>garden because /bin/sh was a symlink to dash which didn't work). Does
>anyone object the change from bash to sh?

What you would want to do is change bash to sh, and ensure that all the 
scripts follows the POSIX standard 100%. Then it will work in both bash,
dash, ksh and *any other* POSIX-compatible shells.

You can read the POSIX standard in HTML format at
http://pubs.opengroup.org/onlinepubs/9699919799/
(You may have to register to view it, but it’s completely free.)

If you have the POSIX man pages installed (you may already have them without 
knowing), you can read the POSIX version documentation of various commands. 
For example, instead of writing

  man mkdir
or
  man 1 mkdir

type

  man 1p mkdir

As you see, the POSIX man pages are *much* more precise (and verbose!), using 
the word ‘shall’ often, leaving no doubt of exactly what each command and 
options should do, in all edge cases. That may make them harder to read, but 
some times they’re actually more clear than the normal man pages.

bash is POSIX compatible (all POSIX commands should work 100%), but you may 
have to set

  export POSIXLY_CORRECT=1

to ensure that bash follows the spec in some rare special cases. (This also 
has an effect on other utilities, like (g)awk.)

bash will still support non-POSIX constructs, though (like using two equals 
sign in tests), so you really should test the scripts in dash, which *doesn’t* 
allow non-POSIX constructs (AFAIK), and is faster too.

This Web page may be useful:
http://mywiki.wooledge.org/Bashism

There also is a ‘checkbashisms’ scripts, which I haven’t tried.

-- 
Karl Ove Hufthammer
http://huftis.org/
Jabber: [email protected]
_______________________________________________
dev-context mailing list
[email protected]
http://www.ntg.nl/mailman/listinfo/dev-context

Reply via email to