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

📄 abs-book.sgml

📁 一本完整的描述Unix Shell 编程的工具书的所有范例
💻 SGML
📖 第 1 页 / 共 5 页
字号:
              <para>In a <link linkend="paramsubref">parameter	        substitution</link> expression, the <token>?</token>		<link linkend="qerrmsg">tests whether a variable has been		set</link>.</para>	  </listitem>	</varlistentry>	<varlistentry>	  <term><token>?</token></term>	  <indexterm>	    <primary>?</primary>	  </indexterm>	  <indexterm>	    <primary>special character</primary>	    <secondary>?</secondary>	  </indexterm>	  <indexterm>	    <primary>wild card</primary>	    <secondary>globbing</secondary>	  </indexterm>	  	  <indexterm>	    <primary>regular expression</primary>	  </indexterm>	  	  <listitem><formalpara><title>wild card</title>	      <para>The <token>?</token> character serves as a		single-character <quote>wild card</quote> for filename		expansion in <link linkend="globbingref">globbing</link>,		as well as <link linkend="quexregex">representing one		character</link> in an <link linkend="extregex">extended		regular expression</link>.</para>	    </formalpara>	  </listitem>	</varlistentry>	<varlistentry><term><token>$</token></term>	  <indexterm>	    <primary>$</primary>	  </indexterm>	  <indexterm>	    <primary>special character</primary>	    <secondary>$</secondary>	  </indexterm>	  <indexterm>	    <primary>variable substitution</primary>	  </indexterm>	  	  <listitem>            <formalpara><title><link linkend="varsubn">Variable              substitution</link> (contents of a variable)</title>             <para>	       <programlisting>var1=5var2=23skidooecho $var1     # 5echo $var2     # 23skidoo</programlisting>	       </para>	       </formalpara>	       <para>A <token>$</token> prefixing a variable name		indicates the <emphasis>value</emphasis> the variable		holds.</para>	  </listitem>	</varlistentry>  	<varlistentry><term><token>$</token></term>	  <indexterm>	    <primary>$</primary>	  </indexterm>	  <indexterm>	    <primary>special character</primary>	    <secondary>$</secondary>	  </indexterm>	  <indexterm>	    <primary>regular expression</primary>	  </indexterm>	  	  <indexterm>	    <primary>end of line</primary>	  </indexterm>	  	  <listitem>	    <formalpara><title>end-of-line</title>	      <para>In a <link linkend="regexref">regular expression</link>, a	        <quote>$</quote> addresses the end of a line of text.</para>	    </formalpara>	    </listitem>	</varlistentry>	<varlistentry><term><token>${}</token></term>	  <indexterm>	    <primary>${}</primary>	  </indexterm>	  <indexterm>	    <primary>special character</primary>	    <secondary>${}</secondary>	  </indexterm>	  <indexterm>	    <primary>parameter substitution</primary>	  </indexterm>	  	  <listitem>            <formalpara><title><link linkend="paramsubref">Parameter              substitution</link></title>             <para></para></formalpara>	  </listitem>	</varlistentry>  	<varlistentry>	  <term><token>$*</token></term>	  <term><token>$@</token></term>	  <indexterm>	    <primary>$*</primary>	  </indexterm>	  <indexterm>	    <primary>special character</primary>	    <secondary>$*</secondary>	  </indexterm>	  <indexterm>	    <primary>$@</primary>	    <secondary>positional parameters</secondary>	  </indexterm>	  	  <indexterm>	    <primary>$@</primary>	  </indexterm>	  	  <listitem><formalpara><title><link linkend="appref">positional	    parameters</link></title>	      <para></para>	    </formalpara>	  </listitem>	</varlistentry>	<varlistentry>	  <term><token>$?</token></term>	  <indexterm>	    <primary>$?</primary>	  </indexterm>	  <indexterm>	    <primary>special character</primary>	    <secondary>?</secondary>	  </indexterm>	  <indexterm>	    <primary>exit status</primary>	    <secondary>variable</secondary>	  </indexterm>	  	  <indexterm>	    <primary>exit status</primary>	  </indexterm>	  	  <listitem><formalpara><title>exit status variable</title>	      <para>The <link linkend="exsref">$? variable</link>	        holds the <link linkend="exitstatusref">exit status</link>		of a command, a <link linkend="functionref">function</link>,		or of the script itself.</para>	    </formalpara>	  </listitem>	</varlistentry>	<varlistentry>	  <term><token>$$</token></term>	  <indexterm>	    <primary>$$</primary>	  </indexterm>	  <indexterm>	    <primary>special character</primary>	    <secondary>$$</secondary>	  </indexterm>	  <indexterm>	    <primary>process ID</primary>	    <secondary>variable</secondary>	  </indexterm>	  	  <indexterm>	    <primary>process ID</primary>	  </indexterm>	  	  <listitem><formalpara><title>process ID variable</title>	      <para>The <link linkend="proccid">$$ variable</link>	        holds the <emphasis>process ID</emphasis> of the script in		which it appears.</para>	    </formalpara>	  </listitem>	</varlistentry>	<varlistentry>	  <term><token>()</token></term>	  <listitem><formalpara><title>command group</title>	      <para><programlisting>(a=hello; echo $a)</programlisting></para>	    </formalpara>	  <important>	  	    <para>A listing of commands within	      <replaceable>parentheses</replaceable> starts a <link	      linkend="subshellsref">subshell</link>.</para>	    <para>Variables inside parentheses, within the subshell, are not	      visible to the rest of the script. The parent process,	      the script, <link linkend="parvis">cannot read variables	      created in the child process</link>, the subshell.	      <programlisting>a=123( a=321; )	      echo "a = $a"   # a = 123# "a" within parentheses acts like a local variable.</programlisting></para>	  </important>	  <formalpara><title>array initialization</title>	    <para><programlisting>Array=(element1 element2 element3)</programlisting></para>	    </formalpara>	  </listitem>	</varlistentry>	<varlistentry>	  <indexterm>	    <primary>{xxx,yyy,zzz..}</primary>	  </indexterm>	  <indexterm>	    <primary>special character</primary>	    <secondary>{}</secondary>	  </indexterm>	  <indexterm>	    <primary>brace expansion</primary>	  </indexterm>	  	  <term><token>{xxx,yyy,zzz,...}</token></term>	  <listitem><formalpara><title>Brace expansion</title>	      <para><anchor id="braceexpref"><programlisting>cat {file1,file2,file3} > combined_file# Concatenates the files file1, file2, and file3 into combined_file.cp file22.{txt,backup}# Copies "file22.txt" to "file22.backup"</programlisting></para>	    </formalpara>	  <para>A command may act upon a comma-separated list of file specs within	  <replaceable>braces</replaceable>.	     <footnote><para>The shell does the <emphasis>brace	       expansion</emphasis>. The command itself acts upon the	       <emphasis>result</emphasis> of the expansion.</para></footnote>	  	  Filename expansion (<link linkend="globbingref">globbing</link>)	  applies to the file specs between the braces.</para>	  <caution>	    <para>No spaces allowed within the braces	    <emphasis>unless</emphasis> the spaces are quoted or escaped.</para>	    	    <para><userinput>echo {file1,file2}\ :{\ A," B",' C'}</userinput></para>	    <para><computeroutput>file1 : A file1 : B file1 : C file2 : A file2 : B file2 : C</computeroutput></para>	   </caution>	  </listitem>	</varlistentry>	<varlistentry>	  <term><token>{}</token></term>	  <indexterm>	    <primary>{}</primary>	  </indexterm>	  <indexterm>	    <primary>special character</primary>	    <secondary>{}</secondary>	  </indexterm>	  <indexterm>	    <primary>block of code</primary>	  </indexterm>	  	  <listitem>	  <para><anchor id="codeblockref"></para>	  <formalpara><title>Block of code [curly brackets]</title>	      <para>Also referred to as an <quote>inline group</quote>,		this construct, in effect, creates an anonymous		function. However, unlike a <link		linkend="functionref">function</link>, the variables		in a code block remain visible to the remainder of the		script.</para></formalpara>	      <para> <screen><prompt>bash$ </prompt><userinput>{ local a;	      a=123; }</userinput><computeroutput>bash: local: can only be used in afunction</computeroutput>	      </screen> </para>	      <para><programlisting>a=123{ a=321; }echo "a = $a"   # a = 321   (value inside code block)# Thanks, S.C.</programlisting></para>	    <para>The code block enclosed in braces may have <link	      linkend="ioredirref">I/O redirected</link> to and from	      it.</para>	    <example id="ex8">	      <title>Code blocks and I/O redirection</title>	      <programlisting>&ex8;</programlisting>	    </example>	    <example id="rpmcheck">	      <title>Saving the results of a code block to a file</title>	      <programlisting>&rpmcheck;</programlisting>	    </example>	    <note><para>Unlike a command group within (parentheses),	      as above, a code block enclosed by {braces} will	      <emphasis>not</emphasis> normally launch a <link	      linkend="subshellsref">subshell</link>.		<footnote><para>Exception: a code block in braces as		  part of a pipe <emphasis>may</emphasis> run as a		  <link linkend="subshellsref">subshell</link>.		<programlisting>ls | { read firstline; read secondline; }#  Error. The code block in braces runs as a subshell,#+ so the output of "ls" cannot be passed to variables within the block.echo "First line is $firstline; second line is $secondline"  # Will not work.# Thanks, S.C.</programlisting></para></footnote>	      </para></note>	  </listitem>	</varlistentry>	<varlistentry>	  <term><token>{} \;</token></term>	  <listitem>	  <formalpara><title>pathname</title>	      <para>Mostly used in <link linkend="findref">find</link>		constructs.  This is <emphasis>not</emphasis> a shell		<link linkend="builtinref">builtin</link>.</para>	    </formalpara>	      <note><para>The <quote><token>;</token></quote> ends		the <option>-exec</option> option of a		<command>find</command> command sequence.  It needs		to be escaped to protect it from interpretation by the		shell.</para></note>	  </listitem>	</varlistentry>	<varlistentry><term><token>[ ]</token></term>	  <indexterm>	    <primary>[]</primary>	  </indexterm>	  <indexterm>	    <primary>special character</primary>	    <secondary>[ ]</secondary>	  </indexterm>	  <indexterm>	    <primary>test</primary>	  </indexterm>	  	  <listitem>            <formalpara><title>test</title>             <para></para></formalpara>	     <para><anchor id="leftbracket"><link	       linkend="ifthen">Test</link> expression between <command>[	       ]</command>.  Note that <command>[</command> is part of	       the shell builtin <command>test</command> (and a synonym	       for it), <emphasis>not</emphasis> a link to the external	       command <filename

⌨️ 快捷键说明

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