Use double-quoted values for expansion and escaping
mainDouble quotes (") provide more flexibility for complex values:
- Variable Expansion: Supports
${VAR}syntax. It is recommended to use braces (e.g.,${BAR}) to ensure consistent behavior across different shells. - Escaping: You must escape backslashes (
\), backticks (`), and dollar signs ($) using a backslash. - Line Continuation: A backslash (
\) at the very end of a line allows you to continue the value on the next line. - No Command Substitution: For security reasons, command substitution (e.g.,
$(command)) is not supported. - Backslashes: Outside of escaping the specific characters mentioned above, backslashes are treated as literal characters.
Valid Examples:
# Variable expansion
BAR="bar"
VALUE="foo ${BAR} baz"
# Escaping
VAR=" \" \` \\ \$ "
# Line continuation
LONGLINE="https://github.com/ko1nksm\
/shdotenv/README.md"Invalid Examples:
VAR=" " ` \ $ "
VAR="$(whoami)"BAR="bar"
VALUE="foo ${BAR} baz"