2017-06-03 23 views
-1

sshをデバッグすると、 "logout"の戻り値は前のコマンドになります。たとえば、"logout"の戻り値は前のコマンドの戻り値です

[server1 ~] $ ssh [email protected] 

/* login server2 from server1 */ 

[[email protected] ~]# it's an bad command 

-bash: it: command not found 

[[email protected] ~]# echo $? 

127 

/* the return value is 127 */ 

[[email protected] ~]# it's an bad command 

-bash: it: command not found 

[[email protected] ~]# logout 

Connection to server1 closed. 

[server1 ~ ]$ echo $? 

127 

/* the return value is 127 too */ 

ログアウトの戻り値がこのように設定されている理由を教えていただけますか?

+0

コードに4つの空白文字を付加します。 [edit-help](http://stackoverflow.com/editing-help)を見てください。 – Cyrus

答えて

1

答えは明らかです:スクリプトのためです。

はsshをせずに行うには、典型的な事を考えてみましょう、と言う:

grep -q crap file 
if [ $? -eq 0 ]; then 
    echo something something 
fi 

あなたは突然、あなただけの接頭辞ができ、リモートマシン上のgrepを実行する必要がありますが、ローカルマシン上の成果に基づいて行動したい場合grepコマンドでsshを起動しても問題ありません。