SSHbash -c 'cmd' , 출력의 첫 번째 줄이 손실되는 이유는 무엇입니까? [복사]

SSHbash -c 'cmd' , 출력의 첫 번째 줄이 손실되는 이유는 무엇입니까? [복사]

쉘 명령 출력이 손실되는 이유는 무엇입니까? (이 예에서는 SSH를 통해 Ubuntu Raspberry Pi에 연결)

$ ssh [email protected] bash -l -c 'echo 111'

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

^^^ 111을 인쇄하지 마세요. 첫 번째 줄이 누락된 것 같습니다.

$ ssh [email protected] bash -l -c 'echo 111 && echo 222'

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.


222

(-l은 아무런 차이가 없습니다)

호스트 컴퓨터에서는 잘 작동합니다.

pi@raspberrypi:~ $ bash -c 'echo 111'
111

답변1

인용 오류로 인해 출력이 손실됩니다.

ssh [email protected] bash -l -c 'echo 111'

bash여기에 실행을 요청하는 호출이 있습니다 echo. 나머지 매개변수가 111제공되지만 bash사용되지는 않습니다. (결과는 빈 줄입니다.)

아마도 당신이 원하는 것은 다음 대안 중 하나입니다.

ssh [email protected] 'echo 111'                 # Shell executing echo

ssh -t [email protected] 'echo 111'              # Interactive shell (with `.bashrc`)  executing echo

ssh [email protected] 'bash -l -c "echo 111"'    # Shell calling login shell (`.bash_profile`) to execute echo

관련 정보