- Infos im HLRS Wiki sind nicht rechtsverbindlich und ohne Gewähr -
- Information contained in the HLRS Wiki is not legally binding and HLRS is not responsible for any damages that might result from its use -

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)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

#!/bin/sh

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.

Examples

Example for a Bash constructs that is not POSIX compliant:

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

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:

http://www.unix.org/single_unix_specification/

http://www.in-ulm.de/~mascheck/various/portability/

http://gondor.apana.org.au/~herbert/dash/