📄 ch44_01.htm
字号:
with command substitution, article<ACLASS="xref"HREF="ch09_16.htm"TITLE="Command Substitution ">9.16</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Find out whether a program worked or failed with its exit status,article<ACLASS="xref"HREF="ch44_07.htm"TITLE="Exit Status of UNIX Processes ">44.7</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Test a program's exit status and do different things if it worked or failed,articles<ACLASS="xref"HREF="ch44_08.htm"TITLE="Test Exit Status with the if Statement ">44.8</A>and<ACLASS="xref"HREF="ch44_09.htm"TITLE="Testing Your Success ">44.9</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Loop through a set of commands and use another command to control that loop,article<ACLASS="xref"HREF="ch44_10.htm"TITLE="Loops That Test Exit Status ">44.10</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Set exit status of a shell (shell script), article<ACLASS="xref"HREF="ch44_11.htm"TITLE="Set Exit Status of a Shell (Script) ">44.11</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Handle interrupts (like CTRL-c) and other signals, article<ACLASS="xref"HREF="ch44_12.htm"TITLE="Trapping Exits Caused by Interrupts ">44.12</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Read input from the keyboard, article<ACLASS="xref"HREF="ch44_13.htm"TITLE="read: Reading from the Keyboard ">44.13</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Handle command-line arguments (options, filenames, etc.), article<ACLASS="xref"HREF="ch44_15.htm"TITLE="Handling Command-Line Arguments in Shell Scripts ">44.15</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Step through arguments, or any list of words, with a <EMCLASS="emphasis">for</EM> loop,articles<ACLASS="xref"HREF="ch09_12.htm"TITLE="The Bourne Shell for Loop ">9.12</A>and<ACLASS="xref"HREF="ch44_16.htm"TITLE="Handling Command-Line Arguments with a for Loop ">44.16</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Handle arguments with the <EMCLASS="emphasis">while</EM> and <EMCLASS="emphasis">shift</EM> commands, article<ACLASS="xref"HREF="ch44_17.htm"TITLE="Handling Arguments with while and shift ">44.17</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Handle command-line arguments in a more standard and portable waywith <EMCLASS="emphasis">getopt</EM>, article<ACLASS="xref"HREF="ch44_18.htm"TITLE="Standard Command-Line Parsing ">44.18</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Set shell options and command-line arguments with the <EMCLASS="emphasis">set</EM> command,article<ACLASS="xref"HREF="ch44_19.htm"TITLE="The Bourne Shell set Command ">44.19</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Test files and strings of characters with the <EMCLASS="emphasis">test</EM> command,article<ACLASS="xref"HREF="ch44_20.htm"TITLE="test: Testing Files and Strings ">44.20</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Pick a name for a new command with no conflict, article<ACLASS="xref"HREF="ch44_21.htm"TITLE="Picking a Name for a New Command ">44.21</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Find the name of a program and use it in the script, article<ACLASS="xref"HREF="ch44_22.htm"TITLE="Finding a Program Name; Multiple Program Names ">44.22</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Use "subprograms" that can change the current environment, article<ACLASS="xref"HREF="ch44_23.htm"TITLE="Reading Files with the . and source Commands ">44.23</A>.</P></LI></UL><PCLASS="para">This chapter discusses only Bourne shell programming.In most cases, the C shell<SPANCLASS="link">isn't great for shell programming (<ACLASS="linkend"HREF="ch47_02.htm"TITLE="C Shell Programming Considered Harmful ">47.2</A>)</SPAN>.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-50013"></A>A note about command versions: unfortunately, the same commands on different versions of UNIX canhave different options.Some Bourne shells are a little different from others.For instance, some<SPANCLASS="link"><EMCLASS="emphasis">test</EM> (<ACLASS="linkend"HREF="ch44_20.htm"TITLE="test: Testing Files and Strings ">44.20</A>)</SPAN>commands have a <EMCLASS="emphasis">-x</EM> option to test for anexecutable file; others don't.As article<ACLASS="xref"HREF="ch46_10.htm"TITLE="A Portable echo Command ">46.10</A>explains,some <EMCLASS="emphasis">echo</EM> commands use a <EMCLASS="emphasis">-n</EM> option to mean "no newline at theend of this string"; others have you put <CODECLASS="literal">\c</CODE> at the end of the string.And so on.Where there are differences, these articles generally use the commands inBerkeley UNIX.If a command doesn't seem to work on your system, check its onlinemanual page or the <EMCLASS="emphasis">sh</EM> manual page.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN></P></DIV></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="PART"HREF="part08.htm"TITLE="VIII. Shell Programming "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: VIII. Shell Programming "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch44_02.htm"TITLE="44.2 Writing a Simple Shell Program "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 44.2 Writing a Simple Shell Program "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">VIII. Shell Programming </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">44.2 Writing a Simple Shell Program </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -