diff --git a/interp/builtin.go b/interp/builtin.go index d4a44abb1..0fad50c4e 100644 --- a/interp/builtin.go +++ b/interp/builtin.go @@ -70,6 +70,7 @@ func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, a r.errf("set: %v\n", err) return 2 } + r.updateExpandOpts() case "shift": n := 1 switch len(args) { diff --git a/interp/interp.go b/interp/interp.go index d6ec81893..151dab270 100644 --- a/interp/interp.go +++ b/interp/interp.go @@ -262,7 +262,6 @@ func Params(args ...string) func(*Runner) error { args = args[1:] } r.Params = args - r.updateExpandOpts() return nil } } @@ -501,6 +500,7 @@ func (r *Runner) Reset() { Exec: r.Exec, Open: r.Open, KillTimeout: r.KillTimeout, + opts: r.opts, // emptied below, to reuse the space Vars: r.Vars, diff --git a/interp/interp_test.go b/interp/interp_test.go index 3bdebbd45..55918325b 100644 --- a/interp/interp_test.go +++ b/interp/interp_test.go @@ -2743,6 +2743,16 @@ func TestRunnerOpts(t *testing.T) { "[[ $PWD == foo ]]", "exit status 1", }, + { + opts(Params("foo")), + "echo $@", + "foo\n", + }, + { + opts(Params("-u", "--", "foo")), + "echo $@; echo $unset", + "foo\nunset: unbound variable\nexit status 1", + }, } p := syntax.NewParser() for i, c := range cases {