Skip to content

Commit

Permalink
Support numeric bash arguments in commands
Browse files Browse the repository at this point in the history
The code that interpolates variables inside commands did not
support numeric arguments. Updated the regex that looks for values
to interpolate.
  • Loading branch information
odino committed Jul 28, 2019
1 parent 22d3447 commit 0597d2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions evaluator/evaluator_test.go
Expand Up @@ -1219,12 +1219,18 @@ func TestCommand(t *testing.T) {
{"`echo hello world`", "hello world"},
}
} else {
executor := "bash"
if runtime.GOOS == "windows" {
executor = "cmd.exe"
}

// bash commands
tests = []testLine{
{`a = "A"; b = "B"; eee = "-e"; $(echo $eee -n $a$a$b$b$c$c)`, "AABB"},
{`$(echo -n "123")`, "123"},
{`$(echo -n hello world)`, "hello world"},
{`$(echo hello world | xargs echo -n)`, "hello world"},
{`$(echo \$0)`, executor},
{`$(echo \$CONTEXT)`, "abs"},
{"a = 'A'; b = 'B'; eee = '-e'; `echo $eee -n $a$a$b$b$c$c`", "AABB"},
{"`echo -n '123'`", "123"},
Expand Down
2 changes: 1 addition & 1 deletion util/util.go
Expand Up @@ -62,7 +62,7 @@ func GetEnvVar(env *object.Environment, varName, defaultVal string) string {
func InterpolateStringVars(str string, env *object.Environment) string {
// Match all strings preceded by
// a $ or a \$
re := regexp.MustCompile("(\\\\)?\\$([a-zA-Z_]{1,})")
re := regexp.MustCompile("(\\\\)?\\$([a-zA-Z_0-9]{1,})")
str = re.ReplaceAllStringFunc(str, func(m string) string {
// If the string starts with a backslash,
// that's an escape, so we should replace
Expand Down

0 comments on commit 0597d2a

Please sign in to comment.