@@ -96,21 +96,29 @@ func showSSHAction(cmd *cobra.Command, args []string) error {
96
96
return formatSSH (w , instName , format , opts )
97
97
}
98
98
99
+ func quoteOption (o string ) string {
100
+ // make sure the shell doesn't swallow quotes in option values
101
+ if strings .ContainsRune (o , '"' ) {
102
+ o = "'" + o + "'"
103
+ }
104
+ return o
105
+ }
106
+
99
107
func formatSSH (w io.Writer , instName , format string , opts []string ) error {
100
108
fakeHostname := "lima-" + instName // corresponds to the default guest hostname
101
109
switch format {
102
110
case showSSHFormatCmd :
103
111
args := []string {"ssh" }
104
112
for _ , o := range opts {
105
- args = append (args , "-o" , o )
113
+ args = append (args , "-o" , quoteOption ( o ) )
106
114
}
107
115
args = append (args , fakeHostname )
108
116
// the args are similar to `limactl shell` but not exactly same. (e.g., lacks -t)
109
117
fmt .Fprintln (w , strings .Join (args , " " )) // no need to use shellescape.QuoteCommand
110
118
case showSSHFormatArgs :
111
119
var args []string
112
120
for _ , o := range opts {
113
- args = append (args , "-o" , o )
121
+ args = append (args , "-o" , quoteOption ( o ) )
114
122
}
115
123
fmt .Fprintln (w , strings .Join (args , " " )) // no need to use shellescape.QuoteCommand
116
124
case showSSHFormatOptions :
0 commit comments