Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

fix: Force bash for non-standard flags to exec #226

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions internal/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,20 @@ coder sh front-end-dev cat ~/config.json`,

func shell(cmd *cobra.Command, cmdArgs []string) error {
ctx := cmd.Context()
command := "sh"
args := []string{"-c"}
var command string
var args []string
if len(cmdArgs) > 1 {
command = "/bin/sh"
args = []string{"-c"}
args = append(args, strings.Join(cmdArgs[1:], " "))
} else {
// Bring user into shell if no command is specified.
shell := "$(getent passwd $(id -u) | cut -d: -f 7)"
name := "-$(basename " + shell + ")"
args = append(args, fmt.Sprintf("exec -a %q %q", name, shell))

// force bash for the '-l' flag to the exec built-in
command = "/bin/bash"
args = []string{"-c"}
args = append(args, fmt.Sprintf("exec -l %q", shell))
}

envName := cmdArgs[0]
Expand Down