skip to content
Alvin Lucillo

Parameter expansion in Bash

/ 1 min read

💻 Tech

If you have a pipeline step that performs az cli, and you want to append the --debug parameter, one of the ways to do that is via parameter expansion in the form of conditional subtitution. sl

The example below appends --debug parameter if $DEBUG_MODE is set and not empty. eval executes the entire command string. The cmd variable is wrapped in double quotes to ensure that the entire string is passed as a single argument to eval. Without the double quotes, the separators such as spaces will break the command structure apart.

cmd="az storage blob list --account-name $ACCT_NAME --account-key $ACCT_KEY --container-name $CONTAINER_NAME ${DEBUG_MODE:+--debug}"

eval "$cmd"