forked from allan2/dotenvy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.env-substitution
27 lines (20 loc) · 1018 Bytes
/
.env-substitution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
VAR=one
VAR_2=two
# Non-existing values are replaced with an empty string
RESULT=$NOPE #value: '' (empty string)
# All the letters after $ symbol are treated as the variable name to replace
RESULT=$VAR #value: 'one'
# Double quotes do not affect the substitution
RESULT="$VAR" #value: 'one'
# Different syntax, same result
RESULT=${VAR} #value: 'one'
# 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'
# The replacement can be escaped with either single quotes or a backslash:
RESULT='$VAR' #value: '$VAR'
RESULT=\$VAR #value: '$VAR'
# Environment variables are used in the substutution and always override the local variables
RESULT=$PATH #value: the contents of the $PATH environment variable
PATH="My local variable value"
RESULT=$PATH #value: the contents of the $PATH environment variable, even though the local variable is defined