@@ -36,6 +36,7 @@ func newShellCommand() *cobra.Command {
36
36
37
37
shellCmd .Flags ().SetInterspersed (false )
38
38
39
+ shellCmd .Flags ().String ("shell" , "" , "shell interpreter, e.g. /bin/bash" )
39
40
shellCmd .Flags ().String ("workdir" , "" , "working directory" )
40
41
return shellCmd
41
42
}
@@ -83,19 +84,19 @@ func shellAction(cmd *cobra.Command, args []string) error {
83
84
return err
84
85
}
85
86
if workDir != "" {
86
- changeDirCmd = fmt .Sprintf ("cd %q || exit 1" , workDir )
87
+ changeDirCmd = fmt .Sprintf ("cd %s || exit 1" , shellescape . Quote ( workDir ) )
87
88
// FIXME: check whether y.Mounts contains the home, not just len > 0
88
89
} else if len (y .Mounts ) > 0 {
89
90
hostCurrentDir , err := os .Getwd ()
90
91
if err == nil {
91
- changeDirCmd = fmt .Sprintf ("cd %q " , hostCurrentDir )
92
+ changeDirCmd = fmt .Sprintf ("cd %s " , shellescape . Quote ( hostCurrentDir ) )
92
93
} else {
93
94
changeDirCmd = "false"
94
95
logrus .WithError (err ).Warn ("failed to get the current directory" )
95
96
}
96
97
hostHomeDir , err := os .UserHomeDir ()
97
98
if err == nil {
98
- changeDirCmd = fmt .Sprintf ("%s || cd %q " , changeDirCmd , hostHomeDir )
99
+ changeDirCmd = fmt .Sprintf ("%s || cd %s " , changeDirCmd , shellescape . Quote ( hostHomeDir ) )
99
100
} else {
100
101
logrus .WithError (err ).Warn ("failed to get the home directory" )
101
102
}
@@ -108,7 +109,16 @@ func shellAction(cmd *cobra.Command, args []string) error {
108
109
}
109
110
logrus .Debugf ("changeDirCmd=%q" , changeDirCmd )
110
111
111
- script := fmt .Sprintf ("%s ; exec $SHELL --login" , changeDirCmd )
112
+ shell , err := cmd .Flags ().GetString ("shell" )
113
+ if err != nil {
114
+ return err
115
+ }
116
+ if shell == "" {
117
+ shell = `"$SHELL"`
118
+ } else {
119
+ shell = shellescape .Quote (shell )
120
+ }
121
+ script := fmt .Sprintf ("%s ; exec %s --login" , changeDirCmd , shell )
112
122
if len (args ) > 1 {
113
123
script += fmt .Sprintf (
114
124
" -c %s" ,
0 commit comments