From c301cf0b9f5525d2a5fb2a565c535349fe781d66 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Sun, 26 Jul 2020 13:49:34 -0500 Subject: [PATCH] Execute exec commands in sh Change-Id: Iddf070b385a92a95933b94f260a5d509a192de5c --- cmd/coder/shell.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/cmd/coder/shell.go b/cmd/coder/shell.go index bf9c43be..644aa5c3 100644 --- a/cmd/coder/shell.go +++ b/cmd/coder/shell.go @@ -5,6 +5,7 @@ import ( "io" "os" "os/signal" + "strings" "time" "github.com/spf13/pflag" @@ -79,19 +80,16 @@ func (cmd *shellCmd) Run(fl *pflag.FlagSet) { } var ( envName = fl.Arg(0) - command = fl.Arg(1) ctx = context.Background() ) - var args []string - if command != "" { - args = fl.Args()[2:] - } - - // Bring user into shell if no command is specified. - if command == "" { - command = "sh" - args = []string{"-c", "exec $(getent passwd $(whoami) | awk -F: '{ print $7 }')"} + command := "sh" + args := []string{"-c"} + if len(fl.Args()) > 1 { + args = append(args, strings.Join(fl.Args()[1:], " ")) + } else { + // Bring user into shell if no command is specified. + args = append(args, "exec $(getent passwd $(whoami) | awk -F: '{ print $7 }')") } err := runCommand(ctx, envName, command, args)