⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exitcodes.html

📁 Shall高级编程
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><HTML><HEAD><TITLE>Exit Codes With Special Meanings</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="Advanced Bash-Scripting Guide"HREF="index.html"><LINKREL="PREVIOUS"TITLE="Awk"HREF="awk.html"><LINKREL="NEXT"TITLE="A Detailed Introduction to I/O and I/O Redirection"HREF="ioredirintro.html"><METAHTTP-EQUIV="Content-Style-Type"CONTENT="text/css"><LINKREL="stylesheet"HREF="common/kde-common.css"TYPE="text/css"><METAHTTP-EQUIV="Content-Type"CONTENT="text/html; charset=iso-8859-1"><METAHTTP-EQUIV="Content-Language"CONTENT="en"><LINKREL="stylesheet"HREF="common/kde-localised.css"TYPE="text/css"TITLE="KDE-English"><LINKREL="stylesheet"HREF="common/kde-default.css"TYPE="text/css"TITLE="KDE-Default"></HEAD><BODYCLASS="APPENDIX"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#AA0000"VLINK="#AA0055"ALINK="#AA0000"STYLE="font-family: sans-serif;"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="awk.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="ioredirintro.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="APPENDIX"><H1><ANAME="EXITCODES"></A>Appendix D. Exit Codes With Special Meanings</H1><P><ANAME="EXITCODESREF"></A></P><DIVCLASS="TABLE"><HR><ANAME="AEN21392"></A><P><B>Table D-1. <ICLASS="FIRSTTERM">Reserved</I> Exit Codes</B></P><TABLEBORDER="1"CLASS="CALSTABLE"><THEAD><TR><THALIGN="LEFT"VALIGN="TOP">Exit Code Number</TH><THALIGN="LEFT"VALIGN="TOP">Meaning</TH><THALIGN="LEFT"VALIGN="TOP">Example</TH><THALIGN="LEFT"VALIGN="TOP">Comments</TH></TR></THEAD><TBODY><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="OPTION">1</TT></TD><TDALIGN="LEFT"VALIGN="TOP">Catchall for general errors</TD><TDALIGN="LEFT"VALIGN="TOP">let "var1 = 1/0"</TD><TDALIGN="LEFT"VALIGN="TOP">Miscellaneous errors, such as <SPANCLASS="QUOTE">"divide by	        zero"</SPAN></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="OPTION">2</TT></TD><TDALIGN="LEFT"VALIGN="TOP">Misuse of shell builtins (according to Bash documentation)</TD><TDALIGN="LEFT"VALIGN="TOP">&nbsp;</TD><TDALIGN="LEFT"VALIGN="TOP">Seldom seen, usually defaults to exit code	      <SPANCLASS="ERRORCODE">1</SPAN></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="OPTION">126</TT></TD><TDALIGN="LEFT"VALIGN="TOP">Command invoked cannot execute</TD><TDALIGN="LEFT"VALIGN="TOP">&nbsp;</TD><TDALIGN="LEFT"VALIGN="TOP">Permission problem or command is not an executable</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="OPTION">127</TT></TD><TDALIGN="LEFT"VALIGN="TOP"><SPANCLASS="QUOTE">"command not found"</SPAN></TD><TDALIGN="LEFT"VALIGN="TOP">&nbsp;</TD><TDALIGN="LEFT"VALIGN="TOP">Possible problem with <TTCLASS="VARNAME">$PATH</TT> or a typo</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="OPTION">128</TT></TD><TDALIGN="LEFT"VALIGN="TOP">Invalid argument to <AHREF="exit-status.html#EXITCOMMANDREF">exit</A></TD><TDALIGN="LEFT"VALIGN="TOP">exit 3.14159</TD><TDALIGN="LEFT"VALIGN="TOP"><BCLASS="COMMAND">exit</B> takes only integer args in the		range <SPANCLASS="RETURNVALUE">0 - 255</SPAN> (see		footnote)</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="OPTION">128+n</TT></TD><TDALIGN="LEFT"VALIGN="TOP">Fatal error signal <SPANCLASS="QUOTE">"n"</SPAN></TD><TDALIGN="LEFT"VALIGN="TOP"><BCLASS="COMMAND">kill -9</B> <TTCLASS="VARNAME">$PPID</TT> of script</TD><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="USERINPUT"><B>$?</B></TT> returns	      <SPANCLASS="ERRORCODE">137</SPAN> (128 + 9)</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="OPTION">130</TT></TD><TDALIGN="LEFT"VALIGN="TOP">Script terminated by Control-C</TD><TDALIGN="LEFT"VALIGN="TOP">&nbsp;</TD><TDALIGN="LEFT"VALIGN="TOP">Control-C is fatal error signal	      <SPANCLASS="ERRORCODE">2</SPAN>, (130 = 128 + 2, see above)</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"><TTCLASS="OPTION">255*</TT></TD><TDALIGN="LEFT"VALIGN="TOP">Exit status out of range</TD><TDALIGN="LEFT"VALIGN="TOP">exit <SPANCLASS="RETURNVALUE">-1</SPAN></TD><TDALIGN="LEFT"VALIGN="TOP"><BCLASS="COMMAND">exit</B> takes only integer args in the	        range <SPANCLASS="ERRORCODE">0 - 255</SPAN></TD></TR></TBODY></TABLE><HR></DIV><P>According to the above table, exit codes <SPANCLASS="ERRORCODE">1 - 2,        126 - 165, and 255</SPAN>	<ANAME="AEN21469"HREF="#FTN.AEN21469">[1]</A>	have special meanings, and should therefore be avoided for	user-specified exit parameters. Ending a script with <BCLASS="COMMAND">exit	127</B> would certainly cause confusion when troubleshooting	(is the error code a <SPANCLASS="QUOTE">"command not found"</SPAN> or a	user-defined one?). However, many scripts use an <BCLASS="COMMAND">exit	1</B> as a general bailout-upon-error. Since exit code	<SPANCLASS="ERRORCODE">1</SPAN> signifies so many possible errors,	it is not particularly useful in debugging.</P><P>There has been an attempt to systematize exit status numbers	(see <TTCLASS="FILENAME">/usr/include/sysexits.h</TT>),	but this is intended for C and C++ programmers. A similar	standard for scripting might be appropriate. The author of	this document proposes restricting user-defined exit codes to	the range <SPANCLASS="RETURNVALUE">64 - 113</SPAN> (in addition to	<SPANCLASS="RETURNVALUE">0</SPAN>, for success), to conform with	the C/C++ standard. This would allot 50 valid codes, and make	troubleshooting scripts more straightforward.</P><P>All user-defined exit codes in the accompanying examples	to this document now conform to this standard, except	where overriding circumstances exist, as in <AHREF="variables2.html#TMDIN">Example 9-2</A>.</P><DIVCLASS="NOTE"><TABLECLASS="NOTE"WIDTH="100%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/note.png"HSPACE="5"ALT="Note"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>Issuing a <AHREF="variables2.html#XSTATVARREF">$?</A> from	the command line after a shell script exits gives	results consistent with the table above only from the	Bash or <ICLASS="FIRSTTERM">sh</I> prompt. Running the	<ICLASS="FIRSTTERM">C-shell</I> or <ICLASS="FIRSTTERM">tcsh</I>	may give different values in some cases.</P></TD></TR></TABLE></DIV></DIV><H3CLASS="FOOTNOTES">Notes</H3><TABLEBORDER="0"CLASS="FOOTNOTES"WIDTH="100%"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="5%"><ANAME="FTN.AEN21469"HREF="exitcodes.html#AEN21469">[1]</A></TD><TDALIGN="LEFT"VALIGN="TOP"WIDTH="95%"><P><ANAME="EXCOOR"></A>Out of range exit values	  can result in unexpected exit codes. An exit value	  greater than <SPANCLASS="ERRORCODE">255</SPAN> returns an	  exit code <AHREF="operations.html#MODULOREF">modulo</A>	  <SPANCLASS="ERRORCODE">256</SPAN>. For example, <BCLASS="COMMAND">exit	  3809</B> gives an exit code of <SPANCLASS="ERRORCODE">225</SPAN>	  (3809 % 256 = 225).</P></TD></TR></TABLE><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="awk.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="index.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="ioredirintro.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Awk</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top">&nbsp;</TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">A Detailed Introduction to I/O and I/O Redirection</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -