diff --git a/expand/expand.go b/expand/expand.go index 3c4343da..5e52ae05 100644 --- a/expand/expand.go +++ b/expand/expand.go @@ -214,6 +214,9 @@ const patMode = pattern.Filenames | pattern.Braces // The config specifies shell expansion options; nil behaves the same as an // empty config. func Pattern(cfg *Config, word *syntax.Word) (string, error) { + if word == nil { + return "", nil + } cfg = prepareConfig(cfg) field, err := cfg.wordField(word.Parts, quoteNone) if err != nil { diff --git a/expand/param.go b/expand/param.go index f876ef0b..07d3e13b 100644 --- a/expand/param.go +++ b/expand/param.go @@ -206,6 +206,9 @@ func (cfg *Config) paramExp(pe *syntax.ParamExp) (string, error) { if err != nil { return "", err } + if orig == "" { + break // nothing to replace + } with, err := Literal(cfg, pe.Repl.With) if err != nil { return "", err diff --git a/interp/interp_test.go b/interp/interp_test.go index d2312412..11ab2873 100644 --- a/interp/interp_test.go +++ b/interp/interp_test.go @@ -509,6 +509,7 @@ var runTests = []runTest{ {"a='abcx1y'; echo ${a//x[[:digit:]]y}", "abc\n"}, {`a=xyz; echo "${a/y/a b}"`, "xa bz\n"}, {"a='foo_interp_missing/bar_interp_missing'; echo ${a//o*a/}", "fr_interp_missing\n"}, + {"a=foobar; echo ${a//a/} ${a///b} ${a///}", "foobr foobar foobar\n"}, { "echo ${a:-b}; echo $a; a=; echo ${a:-b}; a=c; echo ${a:-b}", "b\n\nb\nc\n",