有趣的bash脚本随记

来自三线的随记

cd "$(dirname "${BASH_SOURCE[0]}")"


domains="${!PARSOID_DOMAIN_*} ${!PARSOID_MWAPIS_*}"

if [ -z "$domains" ]; then
    echo >&2 'You must provide PARSOID_DOMAIN_* variables, for example: export PARSOID_DOMAIN_localhost=http://localhost/w/api.php'
    exit 2;
fi


# see https://www.mediawiki.org/wiki/Parsoid/Setup#Configuration
for var in $domains
do
    if [ -z "${!var}" ]; then
        echo >&2 "The $var variable must not be an empty string";
    fi

    cat <<EOT >> config.yaml
          -
            uri: '${!var}'
            domain: '${var:15}'
EOT
done


https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion