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使用されません。 (結果は空行です。)

おそらくあなたが望むものは、次の選択肢の1つです。

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

おすすめ記事