- Infos im HLRS Wiki sind nicht rechtsverbindlich und ohne Gewähr -

POSIX compliant shell scripting

From HLRS Platforms
Revision as of 12:57, 25 February 2010 by Hpcaschu (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

POSIX compliant shell scripting is important if you want to write/use portable shell scripts. Basically, a generic shell script starts with:


which in itself is a link to a shell interpreter - like bash, ksh, etc.

Some popular shell languages are POSIX-compliant (Bash, Korn shell), but even they offer additional non-POSIX features which will not always function on other shells.


Example for a Bash constructs that is not POSIX compliant:

    for ((n=1;$n <= $wn_slots; ++n)); do
          echo $n

The commands test expression is identical to the command [expression] . In fact, many sources recommend using the brackets for better readability.

  if test "$str1" = "$str2"   if ["$str1" = "$str2" ]
  then                        then
  ...                         ...
  fi                          fi

Note: There is also the extended test facility which is not POSIX compliant and uses double brackets.

I recommend the Dash shell as a very minimalistic POSIX compliant shell

Relevant links: