2016-10-25 7 views
2

私は最後に実行されたコマンドが正しいことを知るために、シェルであることを知り、 "echo $?"コマンドを使用します。 なぜ2を出力として返すのか、それは何を意味しますか?

答えて

3

あなたはそのコマンドのmanページを開く?。$をエコーする前に最後のコマンドを焦点を当てるべきです。終了コードの意味を見つけることができます。

たとえば、

man grep; 
... 
EXIT STATUS 
The exit status is 0 if selected lines are found, and 1 if not found. 
If an error occurred the exit status is 2. 
(Note: POSIX error handling code should check for '2' or greater.) 
.... 

または

man ls; 

    Exit status: 
     0  if OK, 

     1  if minor problems (e.g., cannot access subdirectory), 

     2  if serious trouble (e.g., cannot access command-line argument). 

または

man diff 

Exit status is 0 if inputs are 
     the same, 1 if different, 2 if trouble. 
2

最後のコマンドのエラーコードを表示するだけです。このリンクをチェックしてください:Linux System Errors

#define ENOENT   2  /* No such file or directory */ 
+0

やDebianタイプ '$猫USR /上/ ASM-ジェネリック/ errnoに-base.h'が含まれます –

関連する問題