抱歉,如果標題不是很不言自明,我正在嘗試在一行中運行一個命令:sshProxyCommandssh -i /home/myuser/.ssh/myprivatekey.pem ec2-user@i-00xxxxxxxxxx -o ProxyCommand="aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"上面的這個命令有效,但是我需要在go中做同樣的事情。func (s SSH) Tunnel() error { parts := strings.Fields(`ssh -i /home/myuser/.ssh/myprivateksy.pem ec2-user@i-00xxxxxxxxxxx`) parts = append(parts, `-o ProxyCommand="aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"`) command := exec.Command(parts[0], parts[1:]...) command.Stderr = os.Stderr command.Stdout = os.Stdout command.Stdin = os.Stdin return command.Run()}但是我得到了這個錯誤:zsh:1: command not found: aws ssm start-session --target i-00Xxxxxxxxxxxx --document-name AWS-StartSSHSession --parameters 'portNumber=22'我試圖把它包含在:strings.Fieldsparts := strings.Fields(`ssh -i /home/myuser/.ssh/myprivateksy.pem ec2-user@i-00xxxxxxxxxxx -o ProxyCommand="aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"`)但是,我有另一個錯誤:zsh:1: unmatched " 我怎樣才能做到這一點?
1 回答

拉丁的傳說
TA貢獻1789條經驗 獲得超8個贊
根據您提供的 shell 輸入,以下各項應該有效:
parts := strings.Fields(`ssh -i /home/myuser/.ssh/myprivateksy.pem ec2-user@i-00xxxxxxxxxxx -o`)
parts = append(parts, `ProxyCommand=aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'`)
這將作為沒有引號的單個參數傳遞后面的部分。外殼處理將刪除這些引號。-o
- 1 回答
- 0 關注
- 154 瀏覽
添加回答
舉報
0/150
提交
取消