Under some answers, I see comments that recommend avoiding shell specific commands in answers.

How do I know which commands, operators, etc exist in all shells? Is there a list of standards?

  • man builtins gives a list of commands. Are those the only commands that I can use in a portable shell script that works in all shells?
  • Can a built-in be shell specific?
  • Do the standards for Linux differ from that of other Unixes?
  • What about syntax? Can punctuation, operators, etc be different in some shells?

2 Answers 2


Greg's Wiki has a post on adapting bash scripts for Dash that points out a lot of 'bashisms' - extra features that are non-standard but are a part of bash. Avoiding those bashisms can help to make your script friendlier to different environments. This particularly answers some of your questions. For instance, yes, there are operators that differ (like ==), but there are a standard Posix set that should work in all environments.

For more thorough reading, you can check out the Posix standard, which all shells should comply to. Particularly, the volume on "Shell & Utilities".

What I find more challenging than the shell differences are the command differences. Many Linux systems have GNU find, but if you're writing a portable script, don't rely on your own man find, because there are lots of systems out there with BSD find, which has a different feature set. If you're writing scripts for busybox, you'll find there are different versions with entirely different ncs. Those are the kinds of things that always get me when I deploy a script to different environments.

For extra reading on good shell scripting practices, there is also a good resource on David Pashley's blog: Writing Robust Bash Shell Scripts

Also, make sure you read Gilles answers and comments on this site. He has lots of tips about making sure you use portable code.


Writing a shell script in a specific shell means having that shell installed. The only standard is to have csh and sh installed over all Unix variants. So, if you wanted your script to run on Solaris, *BSD, and GNU then you would have to write it in, say, the Bourne shell.

However, most Unix commands have different syntaxes under different implementations -- look at ps under Solaris, FreeBSD, and GNU -- so depending on what tools you use, your script may not be portable anyway. Where the shell is installed will matter as well. Is it /bin/bash /usr/bin/bash, /usr/local/bin/bash, or somewhere else?

I am unaware of any standards defining a shell. Have a look at rc or`">es for weird non-standard shells. However, those seem to still conform to some common ideas.

  • 7
    POSIX defines sh.
    – Random832
    Sep 12, 2011 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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