Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kmkaplan opened this issue May 5, 2020 · 1 comment

Comments

@kmkaplan
Copy link

kmkaplan commented May 5, 2020

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
Copy link
Contributor

Plecra commented Jun 25, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants