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

Expand existing variables #29

Closed
jpvillaisaza opened this issue Oct 10, 2016 · 4 comments
Closed

Expand existing variables #29

jpvillaisaza opened this issue Oct 10, 2016 · 4 comments

Comments

@jpvillaisaza
Copy link
Member

I would like to use a .env file like the following:

FOO=${HOME}/.foo

After loading the file, FOO should be /home/jpvi/.foo or something like that.

@jsl Let me know if this makes sense and I can take a look.

@jsl
Copy link
Member

jsl commented Oct 11, 2016

@jpvillaisaza I think that this is a good initiative. Thanks for opening this issue. We should think about how other libraries implement this sort of feature, and think critically about the best way to proceed.

I noticed that:

  1. Dotenv for Node.js has variable expansion as a separate module.
  2. Ruby dotenv does tilde expansion.
  3. Python has notes about possible POSIX-compliant variable expansion.

I agree with the general idea of adding functionality to the dotenv templates. However, we may just want to proceed slowly, and based on standards wherever possible so that we don't introduce something that we regret later. We may also want to separate the notion of path expansion from full POSIX-compliant variable expansion and consider those two separately.

What do you think?

@jpvillaisaza
Copy link
Member Author

@jsl Yes, sounds good. I saw the issue for the Python one before opening this issue. I don't have experience with this library (use or development), so I can start taking a look and we can add notes here to think of the best way.

@habibalamin
Copy link
Contributor

habibalamin commented Feb 21, 2017

I ran a test using the dotenvgem, and I think their implementation is sensible. Given how many different implementations of dotenv there are in different languages, I think a standard may be useful to codify.

.env file:

START='this is a test' # test with spaces
REFERENCE_TO_START=$START

UNQUOTED_REFERENCE=$HOME
UNQUOTED_REFERENCE_WITH_EXTRA=$HOME_abc
UNQUOTED_REFERENCE_WITH_BRACES=${HOME}
UNQUOTED_REFERENCE_WITH_BRACES_AND_EXTRA=${HOME}_abc

SINGLE_QUOTED_REFERENCE='$HOME'
SINGLE_QUOTED_REFERENCE_WITH_EXTRA='$HOME_abc'
SINGLE_QUOTED_REFERENCE_WITH_BRACES='${HOME}'
SINGLE_QUOTED_REFERENCE_WITH_BRACES_AND_EXTRA='${HOME}_abc'

DOUBLE_QUOTED_REFERENCE="$HOME"
DOUBLE_QUOTED_REFERENCE_WITH_EXTRA="$HOME_abc"
DOUBLE_QUOTED_REFERENCE_WITH_BRACES="${HOME}"
DOUBLE_QUOTED_REFERENCE_WITH_BRACES_AND_EXTRA="${HOME}_abc"

UNQUOTED_SHELL_INTERPOLATION_WITH_PARENS=$(whoami)
UNQUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS=`whoami`
UNQUOTED_SHELL_INTERPOLATION_WITH_PARENS_AND_EXTRA=$(whoami)_abc
UNQUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS_AND_EXTRA=`whoami`_abc

SINGLE_QUOTED_SHELL_INTERPOLATION_WITH_PARENS='$(whoami)'
SINGLE_QUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS='`whoami`'
SINGLE_QUOTED_SHELL_INTERPOLATION_WITH_PARENS_AND_EXTRA='$(whoami)_abc'
SINGLE_QUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS_AND_EXTRA='`whoami`_abc'

DOUBLE_QUOTED_SHELL_INTERPOLATION_WITH_PARENS="$(whoami)"
DOUBLE_QUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS="`whoami`"
DOUBLE_QUOTED_SHELL_INTERPOLATION_WITH_PARENS_AND_EXTRA="$(whoami)_abc"
DOUBLE_QUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS_AND_EXTRA="`whoami`_abc"

Output of each variable (puts "VARIABLE: #{ENV['VARIABLE']}"):

START: this is a test
REFERENCE_TO_START: this is a test

UNQUOTED_REFERENCE: /Users/Habib
UNQUOTED_REFERENCE_WITH_EXTRA:
UNQUOTED_REFERENCE_WITH_BRACES: /Users/Habib
UNQUOTED_REFERENCE_WITH_BRACES_AND_EXTRA: /Users/Habib_abc

SINGLE_QUOTED_REFERENCE: $HOME
SINGLE_QUOTED_REFERENCE_WITH_EXTRA: $HOME_abc
SINGLE_QUOTED_REFERENCE_WITH_BRACES: ${HOME}
SINGLE_QUOTED_REFERENCE_WITH_BRACES_AND_EXTRA: ${HOME}_abc

DOUBLE_QUOTED_REFERENCE: /Users/Habib
DOUBLE_QUOTED_REFERENCE_WITH_EXTRA:
DOUBLE_QUOTED_REFERENCE_WITH_BRACES: /Users/Habib
DOUBLE_QUOTED_REFERENCE_WITH_BRACES_AND_EXTRA: /Users/Habib_abc

UNQUOTED_SHELL_INTERPOLATION_WITH_PARENS: Habib
UNQUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS: `whoami`
UNQUOTED_SHELL_INTERPOLATION_WITH_PARENS_AND_EXTRA: Habib_abc
UNQUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS_AND_EXTRA: `whoami`_abc

SINGLE_QUOTED_SHELL_INTERPOLATION_WITH_PARENS: $(whoami)
SINGLE_QUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS: `whoami`
SINGLE_QUOTED_SHELL_INTERPOLATION_WITH_PARENS_AND_EXTRA: $(whoami)_abc
SINGLE_QUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS_AND_EXTRA: `whoami`_abc

DOUBLE_QUOTED_SHELL_INTERPOLATION_WITH_PARENS: Habib
DOUBLE_QUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS: `whoami`
DOUBLE_QUOTED_SHELL_INTERPOLATION_WITH_PARENS_AND_EXTRA: Habib_abc
DOUBLE_QUOTED_SHELL_INTERPOLATION_WITH_BACKTICKS_AND_EXTRA: `whoami`_abc

@CristhianMotoche
Copy link
Collaborator

CristhianMotoche commented May 11, 2017

I think we can close this issue, because of #42
Thanks a lot @habibalamin

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

No branches or pull requests

5 participants