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

📄 special-chars.html

📁 Shall高级编程
💻 HTML
📖 第 1 页 / 共 5 页
字号:
></TR></TABLE></P></TD></TR></TABLE></DIV><DIVCLASS="FORMALPARA"><P><B>array initialization. </B><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;Array=(element1 element2 element3)</PRE></TD></TR></TABLE></P></DIV></DD><DT><SPANCLASS="TOKEN">{xxx,yyy,zzz,...}</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>Brace expansion. </B><ANAME="BRACEEXPREF"></A><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;cat {file1,file2,file3} &#62; combined_file   2&nbsp;# Concatenates the files file1, file2, and file3 into combined_file.   3&nbsp;   4&nbsp;   5&nbsp;cp file22.{txt,backup}   6&nbsp;# Copies "file22.txt" to "file22.backup"</PRE></TD></TR></TABLE></P></DIV><P>A command may act upon a comma-separated list of file specs within	  <TTCLASS="REPLACEABLE"><I>braces</I></TT>.	     <ANAME="AEN1000"HREF="#FTN.AEN1000">[3]</A>	  	  Filename expansion (<AHREF="globbingref.html">globbing</A>)	  applies to the file specs between the braces.</P><DIVCLASS="CAUTION"><TABLECLASS="CAUTION"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/caution.png"HSPACE="5"ALT="Caution"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>No spaces allowed within the braces	    <SPANCLASS="emphasis"><ICLASS="EMPHASIS">unless</I></SPAN> the spaces are quoted or escaped.</P><P><TTCLASS="USERINPUT"><B>echo {file1,file2}\ :{\ A," B",' C'}</B></TT></P><P><TTCLASS="COMPUTEROUTPUT">file1 : A file1 : B file1 : C file2 : A file2 : B file2 : C</TT></P></TD></TR></TABLE></DIV></DD><DT><ANAME="BRACEEXPREF33"></A><SPANCLASS="TOKEN">{a..z}</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>Extended Brace expansion. </B><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;echo {a..z} # a b c d e f g h i j k l m n o p q r s t u v w x y z   2&nbsp;# Echoes characters between a and z.   3&nbsp;   4&nbsp;echo {0..3} # 0 1 2 3   5&nbsp;# Echoes characters between 0 and 3.</PRE></TD></TR></TABLE>	      </P></DIV><P>The <ICLASS="FIRSTTERM">{a..z}</I>	    <AHREF="bashver3.html#BRACEEXPREF3">extended brace	    expansion</A> construction is a feature introduced	    in <AHREF="bashver3.html#BASH3REF">version 3</A> of	    <ICLASS="FIRSTTERM">Bash</I>.</P></DD><DT><ANAME="CODEBLOCKREF"></A><SPANCLASS="TOKEN">{}</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>Block of code [curly brackets]. </B>Also referred to as an <ICLASS="FIRSTTERM">inline group</I>,		this construct, in effect, creates an <ICLASS="FIRSTTERM">anonymous		function</I> (a function without a		name). However, unlike in a <SPANCLASS="QUOTE">"standard"</SPAN> <AHREF="functions.html#FUNCTIONREF">function</A>, the variables		inside a code block remain visible to the remainder of the		script.</P></DIV><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>{ local a;	      a=123; }</B></TT> <TTCLASS="COMPUTEROUTPUT">bash: local: can only be used in afunction</TT> 	      </PRE></TD></TR></TABLE> </P><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;a=123   2&nbsp;{ a=321; }   3&nbsp;echo "a = $a"   # a = 321   (value inside code block)   4&nbsp;   5&nbsp;# Thanks, S.C.</PRE></TD></TR></TABLE></P><P><ANAME="BLOCKIO"></A></P><P>The code block enclosed in braces may have <AHREF="io-redirection.html#IOREDIRREF">I/O redirected</A> to and from	      it.</P><DIVCLASS="EXAMPLE"><HR><ANAME="EX8"></A><P><B>Example 3-1. Code blocks and I/O redirection</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# Reading lines in /etc/fstab.   3&nbsp;   4&nbsp;File=/etc/fstab   5&nbsp;   6&nbsp;{   7&nbsp;read line1   8&nbsp;read line2   9&nbsp;} &#60; $File  10&nbsp;  11&nbsp;echo "First line in $File is:"  12&nbsp;echo "$line1"  13&nbsp;echo  14&nbsp;echo "Second line in $File is:"  15&nbsp;echo "$line2"  16&nbsp;  17&nbsp;exit 0  18&nbsp;  19&nbsp;# Now, how do you parse the separate fields of each line?  20&nbsp;# Hint: use awk, or . . .  21&nbsp;# . . . Hans-Joerg Diers suggests using the "set" Bash builtin.</PRE></TD></TR></TABLE><HR></DIV><P><ANAME="BLOCKIO2"></A></P><DIVCLASS="EXAMPLE"><HR><ANAME="RPMCHECK"></A><P><B>Example 3-2. Saving the output of a code block to a file</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# rpm-check.sh   3&nbsp;   4&nbsp;#  Queries an rpm file for description, listing,   5&nbsp;#+ and whether it can be installed.   6&nbsp;#  Saves output to a file.   7&nbsp;#    8&nbsp;#  This script illustrates using a code block.   9&nbsp;  10&nbsp;SUCCESS=0  11&nbsp;E_NOARGS=65  12&nbsp;  13&nbsp;if [ -z "$1" ]  14&nbsp;then  15&nbsp;  echo "Usage: `basename $0` rpm-file"  16&nbsp;  exit $E_NOARGS  17&nbsp;fi    18&nbsp;  19&nbsp;{ # Begin code block.  20&nbsp;  echo  21&nbsp;  echo "Archive Description:"  22&nbsp;  rpm -qpi $1       # Query description.  23&nbsp;  echo  24&nbsp;  echo "Archive Listing:"  25&nbsp;  rpm -qpl $1       # Query listing.  26&nbsp;  echo  27&nbsp;  rpm -i --test $1  # Query whether rpm file can be installed.  28&nbsp;  if [ "$?" -eq $SUCCESS ]  29&nbsp;  then  30&nbsp;    echo "$1 can be installed."  31&nbsp;  else  32&nbsp;    echo "$1 cannot be installed."  33&nbsp;  fi    34&nbsp;  echo              # End code block.  35&nbsp;} &#62; "$1.test"       # Redirects output of everything in block to file.  36&nbsp;  37&nbsp;echo "Results of rpm test in file $1.test"  38&nbsp;  39&nbsp;# See rpm man page for explanation of options.  40&nbsp;  41&nbsp;exit 0</PRE></TD></TR></TABLE><HR></DIV><DIVCLASS="NOTE"><TABLECLASS="NOTE"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/note.png"HSPACE="5"ALT="Note"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>Unlike a command group within (parentheses),	      as above, a code block enclosed by {braces} will	      <SPANCLASS="emphasis"><ICLASS="EMPHASIS">not</I></SPAN> normally launch a <AHREF="subshells.html#SUBSHELLSREF">subshell</A>.		<ANAME="AEN1075"HREF="#FTN.AEN1075">[4]</A>	      </P></TD></TR></TABLE></DIV></DD><DT><SPANCLASS="TOKEN">{}</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>placeholder for text. </B>Used after <AHREF="moreadv.html#XARGSCURLYREF">xargs		<TTCLASS="OPTION">-i</TT></A> (<ICLASS="FIRSTTERM">replace		strings</I> option). The <SPANCLASS="TOKEN">{}</SPAN> double		curly brackets are a placeholder for output text.</P></DIV><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;ls . | xargs -i -t cp ./{} $1   2&nbsp;#            ^^         ^^   3&nbsp;   4&nbsp;# From "ex42.sh" (copydir.sh) example.</PRE></TD></TR></TABLE></P></DD><DT><SPANCLASS="TOKEN">{} \;</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>pathname. </B>Mostly used in <AHREF="moreadv.html#FINDREF">find</A>		constructs.  This is <SPANCLASS="emphasis"><ICLASS="EMPHASIS">not</I></SPAN> a shell		<AHREF="internal.html#BUILTINREF">builtin</A>.</P></DIV><DIVCLASS="NOTE"><TABLECLASS="NOTE"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/note.png"HSPACE="5"ALT="Note"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>The <SPANCLASS="QUOTE">"<SPANCLASS="TOKEN">;</SPAN>"</SPAN> ends		the <TTCLASS="OPTION">-exec</TT> option of a		<BCLASS="COMMAND">find</B> command sequence.  It needs		to be escaped to protect it from interpretation by the		shell.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="LEFTBRACKET"></A><SPANCLASS="TOKEN">[ ]</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>test. </B><ANAME="BRACKTEST"></A></P></DIV><P><AHREF="tests.html#IFTHEN">Test</A> expression between	       <BCLASS="COMMAND">[ ]</B>.	Note that <BCLASS="COMMAND">[</B>	       is part of the shell <ICLASS="FIRSTTERM">builtin</I> <AHREF="tests.html#TTESTREF">test</A> (and a synonym for it),	       <SPANCLASS="emphasis"><ICLASS="EMPHASIS">not</I></SPAN> a link to the external command	       <TTCLASS="FILENAME">/usr/bin/test</TT>.</P></DD><DT><SPANCLASS="TOKEN">[[ ]]</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>test. </B></P></DIV><P>Test expression between <SPANCLASS="TOKEN">[[ ]]</SPAN>. This is a shell	       <AHREF="internal.html#KEYWORDREF">keyword</A>.</P><P>See the discussion on the <AHREF="tests.html#DBLBRACKETS">[[ ... ]] construct</A>.</P></DD><DT><SPANCLASS="TOKEN">[ ]</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>array element. </B></P></DIV><P>In the context of an <AHREF="arrays.html#ARRAYREF">array</A>,	       brackets set off the numbering of each element of that array.	         <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;Array[1]=slot_1   2&nbsp;echo ${Array[1]}</PRE></TD></TR></TABLE></P></DD><DT><SPANCLASS="TOKEN">[ ]</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>range of characters. </B></P></DIV><P>As part of a <AHREF="regexp.html#REGEXREF">regular	       expression</A>, brackets delineate a <AHREF="regexp.html#BRACKETSREF">range of characters</A> to	       match.</P></DD><DT><SPANCLASS="TOKEN">(( ))</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B>integer expansion. </B></P></DIV><P>Expand and evaluate integer expression between	       <SPANCLASS="TOKEN">(( ))</SPAN>.</P><P>See the discussion on the <AHREF="dblparens.html">(( ... )) construct</A>.</P></DD><DT><SPANCLASS="TOKEN">&#62;</SPAN> <SPANCLASS="TOKEN">&#38;&#62;</SPAN> <SPANCLASS="TOKEN">&#62;&#38;</SPAN> <SPANCLASS="TOKEN">&#62;&#62;</SPAN> <SPANCLASS="TOKEN">&#60;</SPAN> <SPANCLASS="TOKEN">&#60;&#62;</SPAN></DT><DD><DIVCLASS="FORMALPARA"><P><B><AHREF="io-redirection.html#IOREDIRREF">redirection</A>. </B></P></DIV><P><TTCLASS="USERINPUT"><B>scriptname &#62;filename</B></TT> redirects the output of	      <TTCLASS="FILENAME">scriptname</TT> to file	      <TTCLASS="FILENAME">filename</TT>. Overwrite	      <TTCLASS="FILENAME">filename</TT> if it already exists.</P><P><ANAME="REDIROUTERROR"></A></P><P><TTCLASS="USERINPUT"><B>command &#38;&#62;filename</B></TT> redirects	      both the <AHREF="ioredirintro.html#STDINOUTDEF"><TTCLASS="FILENAME">stdout</TT></A>	      and the	      <TTCLASS="FILENAME">stderr</TT> of <TTCLASS="FILENAME">command</TT>	      to <TTCLASS="FILENAME">filename</TT>.</P><P><ANAME="REDIROUTERROR2"></A></P><P><TTCLASS="USERINPUT"><B>command &#62;&#38;2</B></TT> redirects	      <TTCLASS="FILENAME">stdout</TT> of <TTCLASS="FILENAME">command</TT>	      to <TTCLASS="FILENAME">stderr</TT>.</P><P><TTCLASS="USERINPUT"><B>scriptname &#62;&#62;filename</B></TT> appends	      the output of <TTCLASS="FILENAME">scriptname</TT>	      to file <TTCLASS="FILENAME">filename</TT>. If	      <TTCLASS="FILENAME">filename</TT> does not already exist,	      it is created.</P><P><ANAME="REDIRRW"></A></P><P><TTCLASS="USERINPUT"><B>[i]&#60;&#62;filename</B></TT>               opens file <TTCLASS="FILENAME">filename</TT> for reading               and writing, and assigns <AHREF="io-redirection.html#FDREF">file               descriptor</A> <SPANCLASS="TOKEN">i</SPAN> to it. If               <TTCLASS="FILENAME">filename</TT> does not exist, it is               created.</P><DIVCLASS="FORMALPARA"><P><B><AHREF="process-sub.html#PROCESSSUBREF">process substitution</A>. </B></P></DIV><P><TTCLASS="USERINPUT"><B>(command)&#62;</B></TT></P><P><TTCLASS="USERINPUT"><B>&#60;(command)</B></TT></P><P><AHREF="comparison-ops.html#LTREF">In a different context</A>,	      the <SPANCLASS="QUOTE">"<SPANCLASS="TOKEN">&#60;</SPAN>"</SPAN> and	      <SPANCLASS="QUOTE">"<SPANCLASS="TOKEN">&#62;</SPAN>"</SPAN> characters act	      as <AHREF="comparison-ops.html#SCOMPARISON1">string comparison	      operators</A>.</P><P><AHREF="comparison-ops.html#INTLT">In yet another context</A>,

⌨️ 快捷键说明

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