dotenv-rs / dotenv

Library to help supply environment variables in testing and development
MIT License
566 stars 45 forks source link

The variable expansion rules are different from the Bourne shell rules #45

Open kmkaplan opened 4 years ago

kmkaplan commented 4 years ago

The rules are different in the shell and in dotenv. This is confusing. Is it possible to adopt the shell rules?

These rules apply to dotenv (from the README):

VAR=one
VAR_2=two
# Curly braces are useful in cases when we need to use a variable with non-alphanumeric name
RESULT=$VAR_2 #value: 'one_2' since $ with no curly braces stops after first non-alphanumeric symbol 
RESULT=${VAR_2} #value: 'two'

In Bourne shell the rules are different:

VAR=one
VAR_2=two
RESULT=$VAR_2 #value: 'two' since $ with no curly braces uses as much as possible
RESULT=${VAR_2} #value: 'two' same thing
RESULT=${VAR}_2 #value: 'one_2', the curly brace mark the end of the variable name
Plecra commented 4 years ago

For something more official, the POSIX specification defines it as "Parameter Expansion" in the same way as the Bourne shell examples.