![SSHbash -c 'cmd' , 출력의 첫 번째 줄이 손실되는 이유는 무엇입니까? [복사]](https://linux55.com/image/210124/SSHbash%20-c%20'cmd'%20%2C%20%EC%B6%9C%EB%A0%A5%EC%9D%98%20%EC%B2%AB%20%EB%B2%88%EC%A7%B8%20%EC%A4%84%EC%9D%B4%20%EC%86%90%EC%8B%A4%EB%90%98%EB%8A%94%20%EC%9D%B4%EC%9C%A0%EB%8A%94%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F%20%5B%EB%B3%B5%EC%82%AC%5D.png)
쉘 명령 출력이 손실되는 이유는 무엇입니까? (이 예에서는 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