💻 Tech
Heredoc — removes the need for \
; it’s straightforward
#!/bin/bash
debug=true
cmd=$(cat <<EOF
az storage blob list
--account-name hello
--output table
${debug:+--debug}"
EOF
)
echo $cmd
# output:
# az storage blob list --account-name hello --output table --debug
Note that since there’s parameter expansion (see ${debug:+--debug}
), <<'EOF'
became <<EOF
to ensure the expansion to happen. Notice that the example above used the one without single quotes. As a side note, using a delimiter with single quote ('EOF
) in Heredoc ensures all the values are string literals, not expanded or evaluated, probably for reasons like security and safety.