Unable to escape backtick
Backticks in variables enclosed in double quotes cannot be escaped with a backslash.
I would like to be able to escape backticks so that my .env file can be sourced as well as parsed with Dotenv.
in my .env file:
NAME="world"
GREETING="\`hello ${NAME}\`"
$ source .env
$ echo $GREETING
`hello world`
But, when the \ is present before the backticks, I get the following error from Dotenv:
>>> Dotenv::createImmutable(dirname(__DIR__), '.env')->load();
Dotenv\Exception\InvalidFileException: Failed to parse dotenv file due to an unexpected escape sequence. Failed at ["\`hello ${NAME}\`"].
If I remove the \ before the backtick, I am unable to run source .env, since hello is interpreted as a command rather than literally:
$ source .env
.env:2: command not found: hello
Single quotes could be used to escape the backticks, but then the ${NAME} would not be expanded.
You can just write the backtick as is, in single quotes.
NAME="world"
GREETING="`hello ${NAME}`"
phpdotenv does not aim for compatibility with source. We have our own feature set and syntax. It is a similar situation for the most popular ruby and python env file parsers too.