POSIX sh

The POSIX shell is available on every Unix system. The quickest way to use it is with the built-in profile:

extensions:
  term:
    profile: sh

This sets shell: sh, prompt: "$", and ps2: ">". No additional configuration is typically needed.

Basic Usage

echo "Hello from sh ($(readlink -f $(which sh) 2>/dev/null || which sh))"
Hello from sh (/usr/bin/dash)

Loops

i=1
while [ $i -le 5 ]; do
  echo "Count: $i"
  i=$((i + 1))
done
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5

Functions

factorial() {
  if [ $1 -le 1 ]; then echo 1
  else echo $(( $1 * $(factorial $(( $1 - 1 ))) ))
  fi
}
factorial 6
720

Text Processing

printf "banana\napple\ncherry\ndate\n" | sort | nl
     1  apple
     2  banana
     3  cherry
     4  date