Shell script

From campisano.org
Jump to navigation Jump to search

POSIX shell

https://pubs.opengroup.org/onlinepubs/9699919799/idx/shell.html

Bash shell

Security

Parameter substitution

#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail



BAR_A_ROOT=1
BAR_A_PATHS=2
BAR_B_ROOT=3
BAR_C_PATHS=4
BAR_D_ROOT=5
BAR_D_PATHS=6


for VAR in ${!BAR_*}
do
    VALUE=${!VAR}
    V=${VAR#BAR_}
    ONE=${V%%_*}
    TWO=${V##*_}
    echo \'$ONE\' \'$TWO\' \'$VALUE\'
done