App portability: /bin/sh

Rose applications are configured to run commands, e.g:

rose-app.conf

[command]
default=my-script "$A" "$B"

[env]
A=1
B=2

These scripts will be executed using /bin/sh.

The exact shell that is used to implement /bin/sh varies depending on the operating system and its configuration. Some operating systems use Bash, others use more lightweight shells such as Dash or Ash. These shells all support the same basic POSIX syntax, but support for more advanced syntax varies.


For example, this Rose application will work on a system where /bin/sh is implemented with Bash, but may fail on other operating systems:

rose-app.conf

[command]
default=set -euo pipefail
       =array=( 1 2 3 )
       =for item in "${array[@]}"; do
       =  do-something "$item"
       =done

The intended usage is to configure a single command, it is recommended to implement scripts in their own file, e.g:

rose-app.conf

[command]
default=my-script

bin/my-script

#!/usr/bin/env bash

set -euo pipefail
array=( 1 2 3 )
for item in "${array[@]}"; do
  do-something "$item"
done