- 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
Jump to navigationJump to search

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: