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

📄 ch45_01.htm

📁 the unix power tools
💻 HTM
📖 第 1 页 / 共 2 页
字号:
explains why you should care.UNIX keeps a file on-disk once it's been opened; as article<ACLASS="xref"HREF="ch45_10.htm"TITLE="Removing a File Once It's Opened&nbsp;- for Security and Easy Cleanup">45.10</A>explains, this has its ups and downs.The <EMCLASS="emphasis">jot</EM> command, article<ACLASS="xref"HREF="ch45_11.htm"TITLE="The Multipurpose jot Command ">45.11</A>,is useful for all kinds of operations with lists of numbers and characters.</P></LI><LICLASS="listitem"><PCLASS="para">Next are techniques for handling variables and parameters.Parameter substitution, explained in article<ACLASS="xref"HREF="ch45_12.htm"TITLE="Parameter Substitution ">45.12</A>,is a compact way to test, set, and give default values for variables.You can use the <CODECLASS="literal">$0</CODE> parameter and UNIX links to make the same scripthave multiple names and do multiple things; see article<ACLASS="xref"HREF="ch45_13.htm"TITLE="Save Disk Space and Programming: Multiple Names for a Program">45.13</A>.Article<ACLASS="xref"HREF="ch45_14.htm"TITLE="Finding the Last Command-Line Argument ">45.14</A>shows the easy way to get the last command-line argument.Article<ACLASS="xref"HREF="ch45_15.htm"TITLE="How to Unset all Command-Line Parameters ">45.15</A>has an easy way to remove all the command-line arguments.</P></LI><LICLASS="listitem"><PCLASS="para">Four articles cover <EMCLASS="emphasis">sh</EM> loops.A <EMCLASS="emphasis">for</EM> loop usually reads a list of single arguments into a singleshell variable.Article<ACLASS="xref"HREF="ch45_16.htm"TITLE="Standard Input to a for Loop ">45.16</A>shows how to make the <EMCLASS="emphasis">for</EM> loop read from standard input.Article<ACLASS="xref"HREF="ch45_17.htm"TITLE="Making a for Loop with Multiple Variables ">45.17</A>has techniques for making a <EMCLASS="emphasis">for</EM> loop set more than one variable.The <EMCLASS="emphasis">dirname</EM> and <EMCLASS="emphasis">basename</EM> commands can be used to split pathnameswith a loop; see article<ACLASS="xref"HREF="ch45_18.htm"TITLE="Using basename and dirname ">45.18</A>.A <EMCLASS="emphasis">while</EM> loop can have more than one command line at the start;see article<ACLASS="xref"HREF="ch45_19.htm"TITLE="A while Loop with Several Loop Control Commands ">45.19</A>.</P></LI><LICLASS="listitem"><PCLASS="para">Next is an assortment of articles about input/output.Article<ACLASS="xref"HREF="ch45_20.htm"TITLE="Overview: Open Files and File Descriptors ">45.20</A>introduces open files and file descriptors&nbsp;- there's more to know aboutstandard input/output/error than you might have realized!Article<ACLASS="xref"HREF="ch45_21.htm"TITLE="n&gt;&amp;m: Swap Standard Output and Standard Error ">45.21</A>has a look at file descriptor handling in the Bourne shell, swappingstandard output and standard error.The shell can redirect the I/O from all commands in a loop at once;article<ACLASS="xref"HREF="ch45_22.htm"TITLE="Handling Files Line-by-Line ">45.22</A>explains one use for this techniqueand article<ACLASS="xref"HREF="ch45_23.htm"TITLE="The Ins and Outs of Redirected I/O Loops ">45.23</A>explains good and bad points of doing this.</P></LI><LICLASS="listitem"><PCLASS="para">The shell can read commands directly from a shell script file.As article<ACLASS="xref"HREF="ch45_24.htm"TITLE="A Shell Can Read a Script from its Standard Input, But...">45.24</A>points out, a shell can also read commands from its standard input, butthat can cause some problems.Article<ACLASS="xref"HREF="ch45_25.htm"TITLE="Shell Scripts On-the-Fly from Standard Input ">45.25</A>shows one place scripts from <EMCLASS="emphasis">stdin</EM> are useful:writing a script that createsanother script as it goes.</P><PCLASS="para">Next are two articles about miscellaneous I/O.One gotcha with the here-document operator (for redirecting input from ascript file) is that the terminators are different in the Bourne and C shells;article<ACLASS="xref"HREF="ch45_26.htm"TITLE="Quoted hereis Document Terminators: sh vs. csh ">45.26</A>explains.Article<ACLASS="xref"HREF="ch45_27.htm"TITLE='Turn Off echo for "Secret&quot; Answers'>45.27</A>shows how to turn off echoing while your script reads a &quot;secret&quot;answer such as a password.</P></LI><LICLASS="listitem"><PCLASS="para">Three articles-<ACLASS="xref"HREF="ch45_28.htm"TITLE="Quick Reference: expr ">45.28</A>,<ACLASS="xref"HREF="ch45_29.htm"TITLE="Testing Characters in a String with expr ">45.29</A>,and<ACLASS="xref"HREF="ch45_30.htm"TITLE="Grabbing Parts of a String ">45.30</A>-show uses for the versatile <EMCLASS="emphasis">expr</EM> expression-handling command.Article<ACLASS="xref"HREF="ch45_31.htm"TITLE="Nested Command Substitution ">45.31</A>.covers multiple <SPANCLASS="link">command substitution (<ACLASS="linkend"HREF="ch09_16.htm"TITLE="Command Substitution ">9.16</A>)</SPAN>.The <EMCLASS="emphasis">grabchars</EM> programin article<ACLASS="xref"HREF="ch45_32.htm"TITLE="A Better read Command: grabchars ">45.32</A>is similar to<SPANCLASS="link"><EMCLASS="emphasis">read</EM> (<ACLASS="linkend"HREF="ch44_13.htm"TITLE="read: Reading from the Keyboard ">44.13</A>)</SPAN>-but <EMCLASS="emphasis">grabchars</EM> doesn't need a RETURN after the answer;<EMCLASS="emphasis">grabchars</EM> also can prompt and do basic tests on the answer.</P><PCLASS="para">Article <ACLASS="xref"HREF="ch45_33.htm"TITLE="Testing Two Strings with One case Statement ">45.33</A>shows a trick for making one<SPANCLASS="link"><EMCLASS="emphasis">case</EM> statement (<ACLASS="linkend"HREF="ch44_05.htm"TITLE="Test String Values with Bourne Shell case ">44.5</A>)</SPAN>test two things at once.Article<ACLASS="xref"HREF="ch45_34.htm"TITLE="Arrays in the Bourne Shell ">45.34</A>has a trick for simulating arrays in the Bourne Shell.Article<ACLASS="xref"HREF="ch45_35.htm"TITLE="Using a Control Character in a Script ">45.35</A>uses <EMCLASS="emphasis">echo</EM> and <EMCLASS="emphasis">tr</EM> to get a control character in a scriptwithout typing the literal character into the file. Finally, article<ACLASS="xref"HREF="ch45_36.htm"TITLE="Shell Lockfile ">45.36</A>has a simple technique for getting exclusive access to a file or othersystem resource.</P></LI></UL><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="SECT1"HREF="ch44_23.htm"TITLE="44.23 Reading Files with the . and source Commands "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 44.23 Reading Files with the . and source Commands "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="ch45_02.htm"TITLE="45.2 The Story of  : #  #! "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 45.2 The Story of  : #  #! "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">44.23 Reading Files with the . and source Commands </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">45.2 The Story of  : #  #! </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 &amp; 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 + -