Possible Duplicate:
Resources for portable shell programming

I want to write a shell script that is intended for further distribution. So I'd like to write it in a way that is as portable as possible; by which I mean that it shouldn't rely on any fancy stuff that is only available in the particular flavour of qzdfsh that I happen to have installed on my own machine. The script will not be very complicated (the worst it will have to do is strip file extensions and test returns from programs).

Where can I find out what stuff is supported in (almost) all shells?

(I'm particularly aware of the fact that /bin/sh is often symlinked to "something else" so simply testing that it works with /bin/sh seems a dubious strategy.)

  • 1
    @Philomath: Yup, looks like it to me. I'll take a look at the resources in that one. (Needless to say, I didn't find that via searching otherwise I wouldn't have asked this one ...). Feel free to close-as-duplicate. If I don't find what I'm looking for, I'll ask a more focussed question. Thanks. – Andrew Stacey Jul 29 '11 at 10:16

While /bin/sh might be a symlink to bash, it still makes a difference. Bash looks how it is invoked, and if invoked as 'sh', either explicitly, or by symlink, or by a parameter/switch, bash will try to act in POSIX mode.

So using a shebang


and starting it as ./script or sh .script should be sufficient.

Not the answer you're looking for? Browse other questions tagged or ask your own question.