diff --git a/expand/expand.go b/expand/expand.go index 1da2f35a7..7c641774f 100644 --- a/expand/expand.go +++ b/expand/expand.go @@ -542,7 +542,6 @@ func (cfg *Config) wordFields(wps []syntax.WordPart) ([][]fieldPart, error) { } curField = append(curField, fp) case *syntax.DblQuoted: - allowEmpty = true if len(x.Parts) == 1 { pe, _ := x.Parts[0].(*syntax.ParamExp) if elems := cfg.quotedElems(pe); elems != nil { @@ -558,6 +557,7 @@ func (cfg *Config) wordFields(wps []syntax.WordPart) ([][]fieldPart, error) { continue } } + allowEmpty = true wfield, err := cfg.wordField(x.Parts, quoteDouble) if err != nil { return nil, err diff --git a/interp/interp_test.go b/interp/interp_test.go index 7c5cf1e58..099c85e7e 100644 --- a/interp/interp_test.go +++ b/interp/interp_test.go @@ -275,6 +275,10 @@ var runTests = []runTest{ {`echo -n "\\"`, `\`}, {`set -- a b c; x="$@"; echo "$x"`, "a b c\n"}, {`set -- b c; echo a"$@"d`, "ab cd\n"}, + {`count() { echo $#; }; set --; count "$@"`, "0\n"}, + {`count() { echo $#; }; set -- ""; count "$@"`, "1\n"}, + {`count() { echo $#; }; a=(); count "${a[@]}"`, "0\n"}, + {`count() { echo $#; }; a=(""); count "${a[@]}"`, "1\n"}, {`echo $1 $3; set -- a b c; echo $1 $3`, "\na c\n"}, {`[[ $0 == "bash" || $0 == "gosh" ]]`, ""},