﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-kenwell-随笔分类-shell</title><link>http://www.cppblog.com/kenwell/category/14098.html</link><description>自己学习所用</description><language>zh-cn</language><lastBuildDate>Wed, 04 Aug 2010 12:12:21 GMT</lastBuildDate><pubDate>Wed, 04 Aug 2010 12:12:21 GMT</pubDate><ttl>60</ttl><item><title>shell 变量间接引用</title><link>http://www.cppblog.com/kenwell/archive/2010/08/02/121977.html</link><dc:creator>c++ 学习</dc:creator><author>c++ 学习</author><pubDate>Mon, 02 Aug 2010 08:46:00 GMT</pubDate><guid>http://www.cppblog.com/kenwell/archive/2010/08/02/121977.html</guid><wfw:comment>http://www.cppblog.com/kenwell/comments/121977.html</wfw:comment><comments>http://www.cppblog.com/kenwell/archive/2010/08/02/121977.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kenwell/comments/commentRss/121977.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kenwell/services/trackbacks/121977.html</trackback:ping><description><![CDATA[<div>这种使用间接引用的方法是一个小技巧. 如果第二个变量更改了它的值, 那么第一个变量</div><div>必须被适当的解除引用(就像上边的例子一样). 幸运的是, 在Bash版本2中引入</div><div>的${!variable}形式使得使用间接引用更加直观了.</div><div><div>假设一个变量的值是第二个变量的名字. 那么我们如何从第一个变量中取得第二个变量的值呢? 比如,</div><div>如果a=letter_of_alphabet并且letter_of_alphabet=z, 那么我们能够通过引用变量a来获得z么? 这确</div><div>实是可以做到的, 它被称为间接引用. 它使用eval var1=\$$var2这种不平常的形式.</div></div>
<img src ="http://www.cppblog.com/kenwell/aggbug/121977.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kenwell/" target="_blank">c++ 学习</a> 2010-08-02 16:46 <a href="http://www.cppblog.com/kenwell/archive/2010/08/02/121977.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux Shell Bash 正则表达式介绍</title><link>http://www.cppblog.com/kenwell/archive/2010/06/30/119014.html</link><dc:creator>c++ 学习</dc:creator><author>c++ 学习</author><pubDate>Wed, 30 Jun 2010 14:15:00 GMT</pubDate><guid>http://www.cppblog.com/kenwell/archive/2010/06/30/119014.html</guid><wfw:comment>http://www.cppblog.com/kenwell/comments/119014.html</wfw:comment><comments>http://www.cppblog.com/kenwell/archive/2010/06/30/119014.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kenwell/comments/commentRss/119014.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kenwell/services/trackbacks/119014.html</trackback:ping><description><![CDATA[<p>正则表达式就是由一系列特殊字符组成的字符串, 其中每个特殊字符都被称为<em>元字符</em>, 这些<em>元字符</em>并不表示为它们字面上的含义, 
而会被解释为一些特定的含义. 具个例子, 比如引用符号, 可能就是表示某人的演讲内容, <em>同上</em>, 也可能表示为我们下面将要讲到的符号的元-含义. 
正则表达式其实是由普通字符和元字符共同组成的集合, 这个集合用来匹配(或指定)模式. </p>
<p>一个正则表达式会包含下列一项或多项:</p><ul>
<li>
<p><em class="FIRSTTERM">一个字符集</em>. 这里所指的字符集只包含普通字符, 这些字符只表示它们的字面含义. 
正则表达式的最简单形式就是<em>只</em>包含字符集, 而不包含元字符. </p></li>
<li>
<p><em class="FIRSTTERM">锚</em>. <em>锚</em>指定了正则表达式所要匹配的文本在文本行中所处的位置. 比如, <span class="TOKEN">^</span>, 和<span class="TOKEN">$</span>就是锚. </p></li>
<li>
<p><em class="FIRSTTERM">修饰符</em>. 它们扩大或缩小(<em>修改</em>)了正则表达式匹配文本的范围. 修饰符包含星号, 括号, 
和反斜杠. </p></li></ul>
<p>正则表达式最主要的目的就是用于(<em class="FIRSTTERM">RE</em>)文本搜索与字符串操作. (译者注: 
以下正则表达式也会被简称为<em>RE</em>.) RE能够<em class="FIRSTTERM">匹配</em>单个字符或者一个字符集 -- 即, 
一个字符串, 或者一个字符串的一部分. </p>
<ul>
<li>
<p>星号 -- <span class="TOKEN">*</span> -- 用来匹配它前面字符的任意多次, <em>包括0次</em>. </p>
<p><span class="QUOTE">"1133*"</span>匹配<tt class="REPLACEABLE"><em>11 + 一个或多个3 + 
也允许后边还有其他字符</em></tt>: <tt class="REPLACEABLE"><em>113</em></tt>, <tt class="REPLACEABLE"><em>1133</em></tt>, <tt class="REPLACEABLE"><em>111312</em></tt>, 等等.</p></li>
<li>
<p><a name="REGEXDOT"></a>点 -- <span class="TOKEN">.</span> -- 用于匹配任意一个字符, 除了换行符. <a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/x13673.html#FTN.AEN13724" name="AEN13724"><span class="footnote">[1]</span></a> </p>
<p><span class="QUOTE">"13."</span> 匹配<tt class="REPLACEABLE"><em>13 + 
至少一个任意字符(包括空格)</em></tt>: <tt class="REPLACEABLE"><em>1133</em></tt>, <tt class="REPLACEABLE"><em>11333</em></tt>, 但不能匹配<tt class="REPLACEABLE"><em>13</em></tt> (因为缺少"."所能匹配的至少一个任意字符). </p></li>
<li>
<p>脱字符号 -- <span class="TOKEN">^</span> -- 匹配行首, 但是某些时候需要依赖上下文环境, 在RE中, 
有时候也表示对一个字符集取反. </p></li>
<li>
<p><a name="DOLLARSIGNREF"></a></p>
<p>美元符 -- <span class="TOKEN">$</span> -- 在RE中用来匹配行尾. </p>
<p><span class="QUOTE">"XXX$"</span> 匹配行尾的<em>XXX</em>. </p>
<p><span class="QUOTE">"^$"</span> 匹配空行. </p></li>
<li>
<p><a name="BRACKETSREF"></a></p>
<p>中括号 -- <span class="TOKEN">[...]</span> -- 在RE中, 将匹配中括号字符集中的某一个字符. </p>
<p><span class="QUOTE">"[xyz]"</span> 将会匹配字符<tt class="REPLACEABLE"><em>x</em></tt>, 
<tt class="REPLACEABLE"><em>y</em></tt>, 或<tt class="REPLACEABLE"><em>z</em></tt>. 
</p>
<p><span class="QUOTE">"[c-n]"</span> 匹配字符<tt class="REPLACEABLE"><em>c</em></tt>到字符<tt class="REPLACEABLE"><em>n</em></tt>之间的任意一个字符. </p>
<p><span class="QUOTE">"[B-Pk-y]"</span> 匹配从<tt class="REPLACEABLE"><em>B</em></tt>到<tt class="REPLACEABLE"><em>P</em></tt>, 或者从<tt class="REPLACEABLE"><em>k</em></tt>到<tt class="REPLACEABLE"><em>y</em></tt>之间的任意一个字符. </p>
<p><span class="QUOTE">"[a-z0-9]"</span> 匹配任意小写字母或数字. </p>
<p><span class="QUOTE">"[^b-d]"</span> 将会匹配范围在<tt class="REPLACEABLE"><em>b</em></tt>到<tt class="REPLACEABLE"><em>d</em></tt><em>之外的</em>任意一个字符. 这就是使用<span class="TOKEN">^</span>对字符集取反的一个实例. (就好像在某些情况下, <span class="TOKEN">!</span>所表达的含义). 
</p>
<p>将多个中括号字符集组合使用, 能够匹配一般的单词或数字. <span class="QUOTE">"[Yy][Ee][Ss]"</span>能够匹配<tt class="REPLACEABLE"><em>yes</em></tt>, <tt class="REPLACEABLE"><em>Yes</em></tt>, 
<tt class="REPLACEABLE"><em>YES</em></tt>, <tt class="REPLACEABLE"><em>yEs</em></tt>, 等等. <span class="QUOTE">"[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]"</span> 
可以匹配社保码(Social Security number). </p></li>
<li>
<p>反斜杠 -- <span class="TOKEN">\</span> -- 用来<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/escapingsection.html#ESCP">转义</a>某个特殊含义的字符, 
这意味着, 这个特殊字符将会被解释为字面含义. </p>
<p><span class="QUOTE">"\$"</span>将会被解释成字符<span class="QUOTE">"$"</span>, 
而不是RE中匹配行尾的特殊字符. 相似的, <span class="QUOTE">"\\"</span>将会被解释为字符<span class="QUOTE">"\"</span>. </p></li>
<li>
<p><a name="ANGLEBRAC"></a></p>
<p><a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/escapingsection.html#ESCP">转义</a>的<span class="QUOTE">"尖括号"</span> -- <span class="TOKEN">\&lt;...\&gt;</span> -- 用于匹配单词边界. 
</p>
<p>尖括号必须被转义才含有特殊的含义, 否则它就表示尖括号的字面含义. </p>
<p><span class="QUOTE">"\&lt;the\&gt;"</span> 完整匹配单词<span class="QUOTE">"the"</span>, 不会匹配<span class="QUOTE">"them"</span>, <span class="QUOTE">"there"</span>, <span class="QUOTE">"other"</span>, 等等. </p>
<p>&#160;</p>
<table style="width: 529px; height: 346px; " border="1" bgcolor="#e0e0e0">
<tbody>
<tr>
<td><font color="#000000"><pre class="SCREEN"><samp class="PROMPT">bash$ </samp><kbd class="USERINPUT">cat textfile</kbd><br><samp class="COMPUTEROUTPUT">This is line 1, of which there is only one instance.<br> This is the only instance of line 2.<br> This is line 3, another line.<br> This is line 4.</samp><br><br><br><samp class="PROMPT">bash$ </samp><kbd class="USERINPUT">grep 'the' textfile</kbd><br><samp class="COMPUTEROUTPUT">This is line 1, of which there is only one instance.<br> This is the only instance of line 2.<br> This is line 3, another line.</samp><br><br><br><samp class="PROMPT">bash$ </samp><kbd class="USERINPUT">grep '\&lt;the\&gt;' textfile</kbd><br><samp class="COMPUTEROUTPUT">This is the only instance of line 2.</samp><br>	      </pre></font></td></tr></tbody></table></li></ul>
<table class="SIDEBAR" border="1" cellpadding="5">
<tbody>
<tr>
<td>
<div class="SIDEBAR"><a name="AEN13844"></a>
<p>要想确定一个RE能否正常工作, 唯一的办法就是测试它. </p>
<table border="0" width="100%" bgcolor="#e0e0e0">
<tbody>
<tr>
<td><font color="#000000"><pre class="PROGRAMLISTING">  1&nbsp;TEST FILE: tstfile                          # 不匹配.<br>  2&nbsp;                                            # 不匹配.<br>  3&nbsp;Run   grep "1133*"  on this file.           # 匹配.<br>  4&nbsp;                                            # 不匹配.<br>  5&nbsp;                                            # 不匹配.<br>  6&nbsp;This line contains the number 113.          # 匹配.<br>  7&nbsp;This line contains the number 13.           # 不匹配.<br>  8&nbsp;This line contains the number 133.          # 不匹配.<br>  9&nbsp;This line contains the number 1133.         # 匹配.<br> 10&nbsp;This line contains the number 113312.       # 匹配.<br> 11&nbsp;This line contains the number 1112.         # 不匹配.<br> 12&nbsp;This line contains the number 113312312.    # 匹配.<br> 13&nbsp;This line contains no numbers at all.       # 不匹配. </pre></font></td></tr></tbody></table>
<table border="1" width="100%" bgcolor="#e0e0e0">
<tbody>
<tr>
<td><font color="#000000"><pre class="SCREEN"><samp class="PROMPT">bash$ </samp><kbd class="USERINPUT">grep "1133*" tstfile</kbd><br><samp class="COMPUTEROUTPUT">Run   grep "1133*"  on this file.           # 匹配.<br> This line contains the number 113.          # 匹配.<br> This line contains the number 1133.         # 匹配.<br> This line contains the number 113312.       # 匹配.<br> This line contains the number 113312312.    # 匹配. </samp><br>	      </pre></font></td></tr></tbody></table></div></td></tr></tbody></table>
<ul>
<li style="LIST-STYLE-TYPE: square">
<div class="FORMALPARA">
<p><strong><a name="EXTREGEX"></a>扩展的正则表达式. </strong>添加了一些额外的匹配字符到基本集合中. 用于<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/textproc.html#EGREPREF">egrep</a>, 
<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/awk.html#AWKREF">awk</a>, 
和<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/wrapper.html#PERLREF">Perl</a>.</p></div></li>
<li>
<p><a name="QUEXREGEX"></a></p>
<p>问号 -- <span class="TOKEN">?</span> -- 匹配它前面的字符, 但是只能匹配1次或0次. 通常用来匹配单个字符. 
</p></li>
<li>
<p><a name="PLUSREF"></a></p>
<p>加号 -- <span class="TOKEN">+</span> -- 匹配它前面的字符, 能够匹配一次或多次. 与前面讲的<span class="TOKEN">*</span>号作用类似, 但是<em>不能</em>匹配0个字符的情况. </p>
<table style="width: 558px; height: 209px; " border="0" bgcolor="#e0e0e0">
<tbody>
<tr>
<td><font color="#000000"><pre class="PROGRAMLISTING">  1&nbsp;# GNU版本的sed和awk能够使用"+",<br>  2&nbsp;# 但是它需要被转义一下. <br>  3&nbsp;<br>  4&nbsp;echo a111b | sed -ne '/a1\+b/p'<br>  5&nbsp;echo a111b | grep 'a1\+b'<br>  6&nbsp;echo a111b | gawk '/a1+b/'<br>  7&nbsp;# 上边3句的作用相同. <br>  8&nbsp;<br>  9&nbsp;# 感谢, S.C.</pre></font></td></tr></tbody></table></li>
<li>
<p><a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/escapingsection.html#ESCP">转义</a><span class="QUOTE">"大括号"</span> -- <span class="TOKEN">\{ \}</span> -- 在转义后的大括号中加上一个数字, 
这个数字就是它前面的RE所能匹配的次数. </p>
<p>大括号必须经过转义, 否则, 大括号仅仅表示字面含意. 这种用法并不是基本RE集合中的一部分, 仅仅是个技巧而以. </p>
<p><span class="QUOTE">"[0-9]\{5\}"</span> 精确匹配5个数字 (所匹配的字符范围是0到9). </p>
<div class="NOTE">
<table class="NOTE" border="0" width="90%">
<tbody>
<tr>
<td valign="top" width="25" align="middle"><img hspace="5" alt="Note" src="file:///D:/users/kenwell/Desktop/Linux%20Shell%20Bash%20%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BB%8B%E7%BB%8D%20-%20Powered%20by%20PHPWind.net_files/2452689_1.gif"></td>
<td valign="top" align="left">
<p>使用大括号形式的RE是不能够在<span class="QUOTE">"经典"</span>(非POSIX兼容)的<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/awk.html#AWKREF">awk</a>版本中正常运行的. 
然而, <strong class="COMMAND">gawk</strong>命令中有一个<code class="OPTION">--re-interval</code>选项, 使用这个选项就允许使用大括号形式的RE了(无需转义). </p>
<p>&#160;</p>
<table style="width: 505px; height: 99px; " border="1" bgcolor="#e0e0e0">
<tbody>
<tr>
<td><font color="#000000"><pre class="SCREEN"><samp class="PROMPT">bash$ </samp><kbd class="USERINPUT">echo 2222 | gawk --re-interval '/2{3}/'</kbd><br><samp class="COMPUTEROUTPUT">2222</samp><br>	      </pre></font></td></tr></tbody></table>
<p><strong class="COMMAND">Perl</strong>与某些版本的<strong class="COMMAND">egrep</strong>不需要转义大括号. </p></td></tr></tbody></table></div></li>
<li>
<p>圆括号 -- <strong class="COMMAND">( )</strong> -- 括起一组正则表达式. 当你想使用<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/moreadv.html#EXPRREF">expr</a>进行<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/string-manipulation.html#EXPRPAREN">子字符串提取(substring 
extraction)</a>的时候, 圆括号就有用了. 如果和下面要讲的<span class="QUOTE">"<span class="TOKEN">|</span>"</span>操作符结合使用, 也非常有用. </p></li>
<li>
<p>竖线 -- <strong class="COMMAND">|</strong> -- 就是RE中的<span class="QUOTE">"或"</span>操作符, 使用它能够匹配一组可选字符中的任意一个. </p>
<p>&#160;</p>
<table style="width: 648px; height: 118px; " border="1" bgcolor="#e0e0e0">
<tbody>
<tr>
<td><font color="#000000"><pre class="SCREEN"><samp class="PROMPT">bash$ </samp><kbd class="USERINPUT">egrep 're(a|e)d' misc.txt</kbd><br><samp class="COMPUTEROUTPUT">People who read seem to be better informed than those who do not.<br> The clarinet produces sound by the vibration of its reed.</samp><br>	      </pre></font></td></tr></tbody></table></li></ul>
<div class="NOTE">
<table class="NOTE" border="0" width="100%">
<tbody>
<tr>
<td valign="top" width="25" align="middle"><img hspace="5" alt="Note" src="file:///D:/users/kenwell/Desktop/Linux%20Shell%20Bash%20%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BB%8B%E7%BB%8D%20-%20Powered%20by%20PHPWind.net_files/2452689_1.gif"></td>
<td valign="top" align="left">
<p>与GNU工具一样, 某些版本的<strong class="COMMAND">sed</strong>, <strong class="COMMAND">ed</strong>, 和<strong class="COMMAND">ex</strong>一样能够支持扩展正则表达式, 
上边这部分就描述了扩展正则表达式. </p></td></tr></tbody></table></div>
<ul>
<li style="LIST-STYLE-TYPE: square">
<div class="FORMALPARA">
<p><strong><a name="POSIXREF"></a>POSIX字符类. </strong><kbd class="USERINPUT">[:class:]</kbd></p></div>
<p>这是另外一种, 用于指定匹配字符范围的方法. </p></li>
<li>
<p><kbd class="USERINPUT">[:alnum:]</kbd> 匹配字母和数字. 等价于<kbd class="USERINPUT">A-Za-z0-9</kbd>. </p></li>
<li>
<p><kbd class="USERINPUT">[:alpha:]</kbd> 匹配字母. 等价于<kbd class="USERINPUT">A-Za-z</kbd>. </p></li>
<li>
<p><kbd class="USERINPUT">[:blank:]</kbd> 匹配一个空格或是一个制表符(tab). </p></li>
<li>
<p><kbd class="USERINPUT">[:cntrl:]</kbd> 匹配控制字符. </p></li>
<li>
<p><kbd class="USERINPUT">[:digit:]</kbd> 匹配(十进制)数字. 等价于<kbd class="USERINPUT">0-9</kbd>. </p></li>
<li>
<p><kbd class="USERINPUT">[:graph:]</kbd> (可打印的图形字符). 匹配ASCII码值范围在33 - 126之间的字符. 
与下面所提到的<kbd class="USERINPUT">[:print:]</kbd>类似, 但是不包括空格字符(空格字符的ASCII码是32). 
</p></li>
<li>
<p><kbd class="USERINPUT">[:lower:]</kbd> 匹配小写字母. 等价于<kbd class="USERINPUT">a-z</kbd>. </p></li>
<li>
<p><kbd class="USERINPUT">[:print:]</kbd> (可打印的图形字符). 匹配ASCII码值范围在32 - 126之间的字符. 
与上边的<kbd class="USERINPUT">[:graph:]</kbd>类似, 但是包含空格. </p></li>
<li>
<p><kbd class="USERINPUT">[:space:]</kbd> 匹配空白字符(空格和水平制表符). </p></li>
<li>
<p><kbd class="USERINPUT">[:upper:]</kbd> 匹配大写字母. 等价于<kbd class="USERINPUT">A-Z</kbd>. </p></li>
<li>
<p><kbd class="USERINPUT">[:xdigit:]</kbd> 匹配16进制数字. 等价于<kbd class="USERINPUT">0-9A-Fa-f</kbd>. </p>
<div class="IMPORTANT">
<table class="IMPORTANT" border="0" width="90%">
<tbody>
<tr>
<td valign="top" width="25" align="middle"><img hspace="5" alt="Important" src="file:///D:/users/kenwell/Desktop/Linux%20Shell%20Bash%20%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BB%8B%E7%BB%8D%20-%20Powered%20by%20PHPWind.net_files/2452689_2.gif"></td>
<td valign="top" align="left">
<p>POSIX字符类通常都要用引号或<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/testconstructs.html#DBLBRACKETS">双中括号</a>([[ 
]])引起来. </p>
<p>&#160;</p>
<table style="width: 497px; height: 99px; " border="1" bgcolor="#e0e0e0">
<tbody>
<tr>
<td><font color="#000000"><pre class="SCREEN"><samp class="PROMPT">bash$ </samp><kbd class="USERINPUT">grep [[:digit:]] test.file</kbd><br><samp class="COMPUTEROUTPUT">abc=723</samp><br>	      </pre></font></td></tr></tbody></table>
<p>如果在一个受限的范围内, 这些字符类甚至可以用在<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/globbingref.html">通配(globbing)</a>中. 
</p>
<p>&#160;</p>
<table style="width: 555px; height: 99px; " border="1" bgcolor="#e0e0e0">
<tbody>
<tr>
<td><font color="#000000"><pre class="SCREEN"><samp class="PROMPT">bash$ </samp><kbd class="USERINPUT">ls -l ?[[:digit:]][[:digit:]]?</kbd><br><samp class="COMPUTEROUTPUT">-rw-rw-r--    1 bozo  bozo         0 Aug 21 14:47 a33b</samp><br>	      </pre></font></td></tr></tbody></table>
<p>如果想了解POSIX字符类在脚本中的使用情况, 请参考<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/textproc.html#EX49">例子 
12-18</a>和<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/textproc.html#LOWERCASE">例子 
12-19</a>. </p></td></tr></tbody></table></div></li></ul>
<p><a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/sedawk.html#SEDREF">Sed</a>, 
<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/awk.html#AWKREF">awk</a>, 
和<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/wrapper.html#PERLREF">Perl</a>在脚本中一般都被用作过滤器, 
这些过滤器将会以RE为参数, 对文件或者I/O流进行"过滤"或转换. 请参考<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/contributed-scripts.html#BEHEAD">例子 
A-12</a>和<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/contributed-scripts.html#TREE">例子 
A-17</a>, 来详细了解这种用法. </p>
<p>对于RE这个复杂的主题, 标准的参考材料是Friedl的<em class="CITETITLE">Mastering Regular 
Expressions</em>. 由Dougherty和Robbins所编写的<em class="CITETITLE">Sed &amp; 
Awk</em>这本书, 也对RE进行了清晰的论述. 如果想获得这些书的更多信息, 请察看<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/biblio.html"><em>参考文献</em></a>. 
</p>
<h3 class="FOOTNOTES">注意事项</h3>
<table class="FOOTNOTES" border="0" width="100%">
<tbody>
<tr>
<td valign="top" width="5%" align="left"><a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/x13673.html#AEN13724" name="FTN.AEN13724"><span class="footnote">[1]</span></a></td>
<td valign="top" width="95%" align="left">
<p>因为<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/sedawk.html#SEDREF">sed</a>, 
<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/awk.html#AWKREF">awk</a>, 
和<a href="http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/textproc.html#GREPREF">grep</a>通常用于处理单行, 
但是不能匹配一个换行符. 如果你想处理多行输入的话, 那么你可以使用"点"来匹配换行符. </p>
<table style="width: 520px; height: 532px; " border="0" bgcolor="#e0e0e0">
<tbody>
<tr>
<td><font color="#000000"><pre class="PROGRAMLISTING">  1&nbsp;#!/bin/bash<br>  2&nbsp;<br>  3&nbsp;sed -e 'N;s/.*/[&amp;]/' &lt;&lt; EOF   # Here Document<br>  4&nbsp;line1<br>  5&nbsp;line2<br>  6&nbsp;EOF<br>  7&nbsp;# 输出:<br>  8&nbsp;# [line1<br>  9&nbsp;# line2]<br> 10&nbsp;<br> 11&nbsp;<br> 12&nbsp;<br> 13&nbsp;echo<br> 14&nbsp;<br> 15&nbsp;awk '{ $0=$1 "\n" $2; if (/line.1/) {print}}' &lt;&lt; EOF<br> 16&nbsp;line 1<br> 17&nbsp;line 2<br> 18&nbsp;EOF<br> 19&nbsp;# 输出:<br> 20&nbsp;# line<br> 21&nbsp;# 1<br> 22&nbsp;<br> 23&nbsp;<br> 24&nbsp;# 感谢, S.C.<br> 25 <br> 26&nbsp;exit 0</pre></font></td></tr></tbody></table></td></tr></tbody></table><p>&nbsp;</p>
<img src ="http://www.cppblog.com/kenwell/aggbug/119014.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kenwell/" target="_blank">c++ 学习</a> 2010-06-30 22:15 <a href="http://www.cppblog.com/kenwell/archive/2010/06/30/119014.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>shell算术表达式操作方法汇总</title><link>http://www.cppblog.com/kenwell/archive/2010/06/28/118870.html</link><dc:creator>c++ 学习</dc:creator><author>c++ 学习</author><pubDate>Mon, 28 Jun 2010 09:03:00 GMT</pubDate><guid>http://www.cppblog.com/kenwell/archive/2010/06/28/118870.html</guid><wfw:comment>http://www.cppblog.com/kenwell/comments/118870.html</wfw:comment><comments>http://www.cppblog.com/kenwell/archive/2010/06/28/118870.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kenwell/comments/commentRss/118870.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kenwell/services/trackbacks/118870.html</trackback:ping><description><![CDATA[
<p class="MsoListParagraph" align="left" style="margin-left:21.0pt;text-align:left;
text-indent:-21.0pt;mso-char-indent-count:0;mso-pagination:widow-orphan;
mso-list:l0 level1 lfo1"><strong style="mso-bidi-font-weight:
normal"><span lang="EN-US" style="font-size:13.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;
mso-fareast-font-family:&quot;Times New Roman&quot;;color:black;mso-font-kerning:0pt"><span style="mso-list:Ignore">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;mso-bidi-font-size:11.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;
mso-fareast-font-family:宋体;color:black;mso-font-kerning:0pt">expr expression</span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;
font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-font-family:宋体;color:black;
mso-font-kerning:0pt"><o:p></o:p></span></strong></p>

<p class="MsoNormal" align="left" style="text-align:left;mso-pagination:widow-orphan;
background:white"><span lang="EN-US" style="font-size:13.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;
mso-fareast-font-family:宋体;color:black;mso-font-kerning:0pt">expr</span><span style="font-size:13.5pt;font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;;mso-bidi-font-family:&quot;Times New Roman&quot;;
color:black;mso-font-kerning:0pt">只能用于一元操作符</span><span lang="EN-US" style="font-size:13.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-font-family:
宋体;color:black;mso-font-kerning:0pt">,</span><span style="font-size:13.5pt;
font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;;mso-bidi-font-family:&quot;Times New Roman&quot;;color:black;
mso-font-kerning:0pt">不支持二元操作符</span><span lang="EN-US" style="font-size:12.0pt;
font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:0pt"><o:p></o:p></span></p>

<p class="MsoNormal" align="left" style="text-align:left;mso-pagination:widow-orphan;
background:white"><span lang="EN-US" style="font-size:8.0pt;mso-bidi-font-size:
11.0pt;font-family:&quot;Courier New&quot;;mso-fareast-font-family:宋体;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:teal;mso-font-kerning:0pt">1</span><span lang="EN-US" style="font-size:8.0pt;mso-bidi-font-size:11.0pt;font-family:&quot;Courier New&quot;;
mso-fareast-font-family:宋体;mso-bidi-font-family:&quot;Times New Roman&quot;;color:black;
mso-font-kerning:0pt"> x=</span><span lang="EN-US" style="font-size:8.0pt;
mso-bidi-font-size:11.0pt;font-family:&quot;Courier New&quot;;mso-fareast-font-family:
宋体;mso-bidi-font-family:&quot;Times New Roman&quot;;color:maroon;mso-font-kerning:0pt">1</span><span lang="EN-US" style="font-size:8.0pt;mso-bidi-font-size:11.0pt;font-family:&quot;Courier New&quot;;
mso-fareast-font-family:宋体;mso-bidi-font-family:&quot;Times New Roman&quot;;color:black;
mso-font-kerning:0pt"><o:p></o:p></span></p>

<p class="MsoNormal" align="left" style="text-align:left;mso-pagination:widow-orphan;
background:white"><span lang="EN-US" style="font-size:8.0pt;mso-bidi-font-size:
11.0pt;font-family:&quot;Courier New&quot;;mso-fareast-font-family:宋体;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:teal;mso-font-kerning:0pt">2</span><span lang="EN-US" style="font-size:8.0pt;mso-bidi-font-size:11.0pt;font-family:&quot;Courier New&quot;;
mso-fareast-font-family:宋体;mso-bidi-font-family:&quot;Times New Roman&quot;;color:black;
mso-font-kerning:0pt"> x=$(expr </span><span lang="EN-US" style="font-size:8.0pt;
mso-bidi-font-size:11.0pt;font-family:&quot;Courier New&quot;;mso-fareast-font-family:
宋体;mso-bidi-font-family:&quot;Times New Roman&quot;;color:purple;mso-font-kerning:0pt">$x</span><span lang="EN-US" style="font-size:8.0pt;mso-bidi-font-size:11.0pt;font-family:&quot;Courier New&quot;;
mso-fareast-font-family:宋体;mso-bidi-font-family:&quot;Times New Roman&quot;;color:black;
mso-font-kerning:0pt"> + </span><span lang="EN-US" style="font-size:8.0pt;
mso-bidi-font-size:11.0pt;font-family:&quot;Courier New&quot;;mso-fareast-font-family:
宋体;mso-bidi-font-family:&quot;Times New Roman&quot;;color:maroon;mso-font-kerning:0pt">1)<o:p></o:p></span></p>

<p class="MsoNormal" align="left" style="text-align:left;mso-pagination:widow-orphan;
background:white"><span lang="EN-US" style="font-size:8.0pt;mso-bidi-font-size:
11.0pt;font-family:&quot;Courier New&quot;;mso-fareast-font-family:宋体;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:maroon;mso-font-kerning:0pt">$x + 1</span><span style="font-size:8.0pt;mso-bidi-font-size:11.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Courier New&quot;;mso-hansi-font-family:&quot;Courier New&quot;;mso-bidi-font-family:&quot;Times New Roman&quot;;
color:maroon;mso-font-kerning:0pt">之间必须有空格</span><span lang="EN-US" style="font-size:13.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-font-family:
宋体;color:black;mso-font-kerning:0pt"><o:p></o:p></span></p>

<p class="MsoListParagraph" align="left" style="margin-left:21.0pt;text-align:left;
text-indent:-21.0pt;mso-char-indent-count:0;mso-pagination:widow-orphan;
mso-list:l0 level1 lfo1"><strong style="mso-bidi-font-weight:
normal"><span lang="EN-US" style="font-size:13.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;
mso-fareast-font-family:&quot;Times New Roman&quot;;color:black;mso-font-kerning:0pt"><span style="mso-list:Ignore">2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;mso-bidi-font-size:11.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;
mso-fareast-font-family:宋体;color:black;mso-font-kerning:0pt">let expression</span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;
font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-font-family:宋体;color:black;
mso-font-kerning:0pt"><o:p></o:p></span></strong></p>

<p class="MsoNormal"><span lang="EN-US">let </span><span style="font-family:宋体;
mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:
宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin">的使用方式</span></p>

<p class="MsoNormal"><span lang="EN-US">x=10</span></p>

<p class="MsoNormal"><span lang="EN-US">let x=$x+1</span></p>

<p class="MsoNormal"><span lang="EN-US">let x+=1</span></p>

<p class="MsoNormal"><span lang="EN-US">let x*=10</span></p>

<p class="MsoNormal"><span style="font-family:宋体;mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">等</span></p>

<p class="MsoNormal"><span lang="EN-US">Let</span><span style="font-family:宋体;
mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:
宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin">没有返回值</span></p>

<p class="MsoListParagraph" align="left" style="margin-left:21.0pt;text-align:left;
text-indent:-21.0pt;mso-char-indent-count:0;mso-pagination:widow-orphan;
mso-list:l0 level1 lfo1"><strong style="mso-bidi-font-weight:
normal"><span lang="EN-US" style="font-size:13.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;
mso-fareast-font-family:&quot;Times New Roman&quot;;color:black;mso-font-kerning:0pt"><span style="mso-list:Ignore">3.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span></strong><strong style="mso-bidi-font-weight:normal"><span style="font-size:13.5pt;mso-bidi-font-size:11.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:black;mso-font-kerning:0pt">使用</span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;
mso-bidi-font-size:11.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-font-family:
宋体;color:black;mso-font-kerning:0pt">$((expression ))</span></strong><strong style="mso-bidi-font-weight:normal"><span style="font-size:13.5pt;mso-bidi-font-size:
11.0pt;font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;;mso-bidi-font-family:&quot;Times New Roman&quot;;color:black;
mso-font-kerning:0pt">或</span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;mso-bidi-font-size:11.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;
mso-fareast-font-family:宋体;color:black;mso-font-kerning:0pt">((expression))</span></strong><strong style="mso-bidi-font-weight:normal"><span style="font-size:13.5pt;mso-bidi-font-size:
11.0pt;font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;;mso-bidi-font-family:&quot;Times New Roman&quot;;color:black;
mso-font-kerning:0pt">形式</span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;
mso-fareast-font-family:宋体;color:black;mso-font-kerning:0pt"><o:p></o:p></span></strong></p>

<p class="MsoNormal"><span lang="EN-US">((expression))</span><span style="font-family:宋体;mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:
Calibri;mso-hansi-theme-font:minor-latin">的使用方法</span></p>

<p class="MsoNormal"><span lang="EN-US">x=10</span></p>

<p class="MsoNormal"><span lang="EN-US">((x+=10))</span></p>

<p class="MsoNormal"><span lang="EN-US">(( expression)) </span><span style="font-family:宋体;mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:
Calibri;mso-hansi-theme-font:minor-latin">用法和</span><span lang="EN-US">let</span><span style="font-family:宋体;mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:
Calibri;mso-hansi-theme-font:minor-latin">类似</span></p>

<p class="MsoNormal"><span lang="EN-US">$(())</span><span style="font-family:宋体;
mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:
宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin">的使用用法</span></p>

<p class="MsoNormal"><span style="font-family:宋体;mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">：</span><span lang="EN-US"> $((x=$x+10))</span></p>

<p class="MsoNormal"><span lang="EN-US">echo $x</span></p>

<p class="MsoNormal"><span lang="EN-US">y=$((x=$x-10))</span></p>

<p class="MsoNormal"><span lang="EN-US">echo $y</span></p>

<p class="MsoNormal"><span lang="EN-US">y=$(($x+1))</span></p>

<p class="MsoNormal"><span lang="EN-US">echo $y</span></p>

<p class="MsoNormal"><span lang="EN-US">echo $x</span></p>

<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>

<p class="MsoListParagraph" align="left" style="margin-left:21.0pt;text-align:left;
text-indent:-21.0pt;mso-char-indent-count:0;mso-pagination:widow-orphan;
mso-list:l0 level1 lfo1"><strong style="mso-bidi-font-weight:
normal"><span lang="EN-US" style="font-size:13.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;
mso-fareast-font-family:&quot;Times New Roman&quot;;color:black;mso-font-kerning:0pt"><span style="mso-list:Ignore">4.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span></strong><strong style="mso-bidi-font-weight:normal"><span style="font-size:13.5pt;mso-bidi-font-size:11.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:black;mso-font-kerning:0pt">使用</span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;
mso-bidi-font-size:11.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-font-family:
宋体;color:black;mso-font-kerning:0pt">$[<span style="mso-spacerun:yes">&nbsp;
</span>]</span></strong><strong style="mso-bidi-font-weight:normal"><span style="font-size:13.5pt;mso-bidi-font-size:11.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:black;mso-font-kerning:0pt">形式</span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;
font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-font-family:宋体;color:black;
mso-font-kerning:0pt"><o:p></o:p></span></strong></p>

<p class="MsoNormal"><span style="font-family:宋体;mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">例如：</span></p>

<p class="MsoNormal"><span lang="EN-US">n=1</span></p>

<p class="MsoNormal"><span lang="EN-US">:<span style="mso-spacerun:yes">&nbsp; </span>$[
n=$n+1 ](</span><span style="font-family:宋体;mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">：和</span><span lang="EN-US">$</span><span style="font-family:宋体;mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">之间有空格</span><span lang="EN-US">)</span></p>

<p class="MsoNormal"><span lang="EN-US">y=$[ n = $n + 1 ]</span></p>

<p class="MsoNormal"><span lang="EN-US">echo $y</span></p>

<p class="MsoNormal"><span lang="EN-US">y=$[ $n+1 ]</span></p>

<p class="MsoNormal"><span lang="EN-US">echo $y</span></p>

<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>

<p class="MsoListParagraph" align="left" style="margin-left:21.0pt;text-align:left;
text-indent:-21.0pt;mso-char-indent-count:0;mso-pagination:widow-orphan;
mso-list:l0 level1 lfo1"><strong style="mso-bidi-font-weight:
normal"><span lang="EN-US" style="font-size:13.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;
mso-fareast-font-family:&quot;Times New Roman&quot;;color:black;mso-font-kerning:0pt"><span style="mso-list:Ignore">5.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span></strong><strong style="mso-bidi-font-weight:normal"><span style="font-size:13.5pt;mso-bidi-font-size:11.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;;mso-bidi-font-family:
&quot;Times New Roman&quot;;color:black;mso-font-kerning:0pt">使用</span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;
mso-bidi-font-size:11.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-font-family:
宋体;color:black;mso-font-kerning:0pt">decalare<span style="mso-spacerun:yes">&nbsp;
</span></span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-font-family:
宋体;color:black;mso-font-kerning:0pt"><o:p></o:p></span></strong></p>

<p class="MsoNormal"><span style="font-family:宋体;mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">例子：</span></p>

<p class="MsoNormal"><span lang="EN-US">decare &#8211;i num</span></p>

<p class="MsoNormal"><span lang="EN-US">num=$num+1</span></p>

<p class="MsoNormal"><span lang="EN-US">echo $num</span></p><img src ="http://www.cppblog.com/kenwell/aggbug/118870.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kenwell/" target="_blank">c++ 学习</a> 2010-06-28 17:03 <a href="http://www.cppblog.com/kenwell/archive/2010/06/28/118870.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Bash Process Substitution(shell 进程替换）</title><link>http://www.cppblog.com/kenwell/archive/2010/06/27/118826.html</link><dc:creator>c++ 学习</dc:creator><author>c++ 学习</author><pubDate>Sun, 27 Jun 2010 09:15:00 GMT</pubDate><guid>http://www.cppblog.com/kenwell/archive/2010/06/27/118826.html</guid><wfw:comment>http://www.cppblog.com/kenwell/comments/118826.html</wfw:comment><comments>http://www.cppblog.com/kenwell/archive/2010/06/27/118826.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kenwell/comments/commentRss/118826.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kenwell/services/trackbacks/118826.html</trackback:ping><description><![CDATA[<div id="content-header" style="margin-bottom: 10px; "><h1 class="title" style="font-family: Arial, sans-serif; font-size: 1.4em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Bash Process Substitution</h1></div><div id="content-area" style="padding-bottom: 20px; "><div id="node-1006985" class="node node-type-story" style="margin-top: 1em; margin-right: 1em; margin-bottom: 1em; margin-left: 1em; "><div class="node-inner"><div class="meta" style="font-size: 0.9em; margin-top: 0.1em; "><div class="submitted">May 22, 2008	 &nbsp;By&nbsp;<a href="http://www.linuxjournal.com/users/mitch-frazier" title="View user profile." style="text-decoration: none; color: rgb(0, 51, 102); ">Mitch Frazier</a></div><div class="terms terms-inline" style="display: block; margin-top: 5px; ">&nbsp;in<ul class="links inline" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; display: inline; "><li class="taxonomy_term_19 first last" style="display: inline; list-style-type: none; padding-top: 0px; padding-right: 0.5em; padding-bottom: 0px; padding-left: 0.5em; "><a href="http://www.linuxjournal.com/taxonomy/term/19" rel="tag" title="" style="text-decoration: none; color: rgb(102, 102, 102); ">HOW-TOs</a></li></ul></div></div><div class="content" style="margin-top: 20px; margin-right: 0px; margin-bottom: 20px; margin-left: 0px; font-family: Georgia, serif; line-height: 1.3em; "><p>In addition to the fairly common forms of&nbsp;<a href="http://www.linuxjournal.com/node/1006966" style="text-decoration: none; color: rgb(0, 51, 102); ">input/output redirection</a>&nbsp;the shell recognizes something called&nbsp;<em>process substitution</em>. Although not documented as a form of input/output redirection, its syntax and its effects are similar.</p><p>The syntax for process substitution is:</p><pre style="overflow-x: auto; overflow-y: auto; ">  &lt;(list)
or
  &gt;(list)
</pre>where each&nbsp;<em>list</em>&nbsp;is a command or a pipeline of commands. The effect of process substitution is to make each list act like a file. This is done by giving the list a&nbsp;<em>name</em>&nbsp;in the file system and then substituting that name in the command line. The list is given a name either by connecting the list to named pipe or by using a file in&nbsp;<tt>/dev/fd</tt>&nbsp;(if supported by the O/S). By doing this, the command simply sees a file name and is unaware that its reading from or writing to a command pipeline.<p>&nbsp;</p><p>To substitute a command pipeline for an input file the syntax is:</p><pre style="overflow-x: auto; overflow-y: auto; ">  command ... &lt;(list) ...
</pre>To substitute a command pipeline for an output file the syntax is:<pre style="overflow-x: auto; overflow-y: auto; ">  command ... &gt;(list) ...
</pre><p>&nbsp;</p><p>At first process substitution may seem rather pointless, for example you might imagine something simple like:</p><pre style="overflow-x: auto; overflow-y: auto; ">  uniq &lt;(sort a)
</pre>to sort a file and then find the unique lines in it, but this is more commonly (and more conveniently) written as:<pre style="overflow-x: auto; overflow-y: auto; ">  sort a | uniq
</pre>The power of process substitution comes when you have multiple command pipelines that you want to connect to a single command.<p>&nbsp;</p><p>For example, given the two files:</p><pre style="overflow-x: auto; overflow-y: auto; ">  # cat a
  e
  d
  c
  b
  a
  # cat b
  g
  f
  e
  d
  c
  b
</pre>To view the lines unique to each of these two unsorted files you might do something like this:<pre style="overflow-x: auto; overflow-y: auto; ">  # sort a | uniq &gt;tmp1
  # sort b | uniq &gt;tmp2
  # comm -3 tmp1 tmp2
  a
        f
        g
  # rm tmp1 tmp2
</pre>With process substitution we can do all this with one line:<pre style="overflow-x: auto; overflow-y: auto; ">  # comm -3 &lt;(sort a | uniq) &lt;(sort b | uniq)
  a
        f
        g
</pre><p>&nbsp;</p><p>Depending on your shell settings you may get an error message similar to:</p><pre style="overflow-x: auto; overflow-y: auto; ">  syntax error near unexpected token `('
</pre>when you try to use process substitution, particularly if you try to use it within a shell script. Process substitution is not a POSIX compliant feature and so it may have to be enabled via:<pre style="overflow-x: auto; overflow-y: auto; ">  set +o posix
</pre>Be careful not to try something like:<pre style="overflow-x: auto; overflow-y: auto; ">  if [[ $use_process_substitution -eq 1 ]]; then
    set +o posix
    comm -3 &lt;(sort a | uniq) &lt;(sort b | uniq)
  fi
</pre>The command&nbsp;<tt>set +o posix</tt>&nbsp;enables not only the execution of process substitution but the recognition of the syntax. So, in the example above the shell tries to parse the process substitution syntax before the "set" command is executed and therefore still sees the process substitution syntax as illegal.<p>&nbsp;</p><p>Of course, note that all shells may not support process substitution, these examples will work with bash.<br><br></p><p><br></p><p><p>进程替换与命令替换很相似. 命令替换把一个命令的结果赋值给一个变量, 比如dir_contents=`ls -</p><p>al`或xref=$( grep word datafile). 进程替换把一个进程的输出提供给另一个进程(换句话说, 它把</p><p>一个命令的结果发给了另一个命令).</p><p>命令替换的模版</p><p>用圆括号扩起来的命令</p><p>&gt;(command)</p><p>&lt;(command)</p><p>启动进程替换. 它使用/dev/fd/&lt;n&gt;文件将圆括号中的进程处理结果发送给另一个进程. [1] (译</p><p>者注: 实际上现代的UNIX类操作系统提供的/dev/fd/n文件是与文件描述符相关的, 整数n指的就</p><p>是进程运行时对应数字的文件描述符)</p><p>在"&lt;"或"&gt;"与圆括号之间是没有空格的. 如果加了空格, 会产生错误.</p><p>bash$ echo &gt;(true)</p><p>/dev/fd/63</p><p>bash$ echo &lt;(true)</p><p>/dev/fd/63</p><p>Bash在两个文件描述符之间创建了一个管道, --fIn和fOut--. true命令的stdin被连接到fOut</p><p>(dup2(fOut, 0)), 然后Bash把/dev/fd/fIn作为参数传给echo. 如果系统缺乏/dev/fd/&lt;n&gt;文件, Bash会</p><p>使用临时文件. (感谢, S.C.)</p><p>进程替换可以比较两个不同命令的输出, 甚至能够比较同一个命令不同选项情况下的输出.</p><p>bash$ comm &lt;(ls -l) &lt;(ls -al)</p><p>total 12</p><p>-rw-rw-r-- 1 bozo bozo 78 Mar 10 12:58 File0</p><p>-rw-rw-r-- 1 bozo bozo 42 Mar 10 12:58 File2</p><p>-rw-rw-r-- 1 bozo bozo 103 Mar 10 12:58 t2.sh</p><p>total 20</p><p>drwxrwxrwx 2 bozo bozo 4096 Mar 10 18:10 .</p><p>drwx------ 72 bozo bozo 4096 Mar 10 17:58 ..</p><p>-rw-rw-r-- 1 bozo bozo 78 Mar 10 12:58 File0</p><p>-rw-rw-r-- 1 bozo bozo 42 Mar 10 12:58 File2</p><p>-rw-rw-r-- 1 bozo bozo 103 Mar 10 12:58 t2.sh</p><p>使用进程替换来比较两个不同目录的内容(可以查看哪些文件名相同, 哪些文件名不同):</p><p>1 diff &lt;(ls $first_directory) &lt;(ls $second_directory)</p><p>一些进程替换的其他用法与技巧:</p><p>1 cat &lt;(ls -l)</p><p>2 # 等价于 ls -l | cat</p><p>3</p><p>4 sort -k 9 &lt;(ls -l /bin) &lt;(ls -l /usr/bin) &lt;(ls -l /usr/X11R6/bin)</p><p>5 # 列出系统3个主要'bin'目录中的所有文件, 并且按文件名进行排序.</p><p>6 # 注意是3个(查一下, 上面就3个圆括号)明显不同的命令输出传递给'sort'.</p><p>7</p><p>8</p><p>9 diff &lt;(command1) &lt;(command2) # 给出两个命令输出的不同之处.</p><p>10</p><p>11 tar cf &gt;(bzip2 -c &gt; file.tar.bz2) $directory_name</p><p>12 # 调用"tar cf /dev/fd/?? $directory_name", 和"bzip2 -c &gt; file.tar.bz2".</p><p>13 #</p><p>14 # 因为/dev/fd/&lt;n&gt;的系统属性,</p><p>15 # 所以两个命令之间的管道不必被命名.</p><p>16 #</p><p>17 # 这种效果可以被模拟出来.</p><p>18 #</p><p>19 bzip2 -c &lt; pipe &gt; file.tar.bz2&amp;</p><p>20 tar cf pipe $directory_name</p><p>21 rm pipe</p><p>22 # 或</p><p>23 exec 3&gt;&amp;1</p><p>24 tar cf /dev/fd/4 $directory_name 4&gt;&amp;1 &gt;&amp;3 3&gt;&amp;- | bzip2 -c &gt; file.tar.bz2 3&gt;&amp;-</p><p>25 exec 3&gt;&amp;-</p><p>26</p><p>27</p><p>28 # 感谢, Stephane Chazelas</p><p>一个读者给我发了一个有趣的例子, 是关于进程替换的, 如下.</p><p>1 # 摘自SuSE发行版中的代码片断:</p><p>2</p><p>3 while read des what mask iface; do</p><p>4 # 这里省略了一些命令...</p><p>5 done &lt; &lt;(route -n)</p><p>6</p><p>7</p><p>8 # 为了测试它, 我们让它做点事.</p><p>9 while read des what mask iface; do</p><p>10 echo $des $what $mask $iface</p><p>11 done &lt; &lt;(route -n)</p><p>12</p><p>13 # 输出:</p><p>14 # Kernel IP routing table</p><p>15 # Destination Gateway Genmask Flags Metric Ref Use Iface</p><p>16 # 127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo</p><p>17</p><p>18</p><p>19</p><p>20 # 就像Stephane Chazelas所给出的那样, 一个更容易理解的等价代码是:</p><p>21 route -n |</p><p>22 while read des what mask iface; do # 管道的输出被赋值给了变量.</p><p>23 echo $des $what $mask $iface</p><p>24 done # 这将产生出与上边相同的输出.</p><p>25 # 然而, Ulrich Gayer指出 . . .</p><p>26 #+ 这个简单的等价版本在while循环中使用了一个子shell,</p><p>27 #+ 因此当管道结束后, 变量就消失了.</p><p>28</p><p>29</p><p>30</p><p>31 # 更进一步, Filip Moritz解释了上面两个例子之间存在一个细微的不同之处,</p><p>32 #+ 如下所示.</p><p>33</p><p>34 (</p><p>35 route -n | while read x; do ((y++)); done</p><p>36 echo $y # $y 仍然没有被声明或设置</p><p>37</p><p>38 while read x; do ((y++)); done &lt; &lt;(route -n)</p><p>39 echo $y # $y 的值为route -n的输出行数.</p><p>40 )</p><p>41</p><p>42 # 一般来说, (译者注: 原书作者在这里并未加注释符号"#", 应该是笔误)</p><p>43 (</p><p>44 : | x=x</p><p>45 # 看上去是启动了一个子shell</p><p>46 : | ( x=x )</p><p>47 # 但</p><p>48 x=x &lt; &lt;(:)</p><p>49 # 其实不是</p><p>50 )</p><p>51</p><p>52 # 当你要解析csv或类似东西的时侯, 这非常有用.</p><p>53 # 事实上, 这就是SuSE的这个代码片断所要实现的功能.</p><p>注意事项</p><p>[1] 这与命名管道(临时文件)具有相同的作用, 并且, 事实上, 命名管道也被同时使用在进程</p><p>替换中.</p></p></div></div></div></div><img src ="http://www.cppblog.com/kenwell/aggbug/118826.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kenwell/" target="_blank">c++ 学习</a> 2010-06-27 17:15 <a href="http://www.cppblog.com/kenwell/archive/2010/06/27/118826.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于bash的管道与进程的几个知识点</title><link>http://www.cppblog.com/kenwell/archive/2010/06/25/118723.html</link><dc:creator>c++ 学习</dc:creator><author>c++ 学习</author><pubDate>Fri, 25 Jun 2010 08:35:00 GMT</pubDate><guid>http://www.cppblog.com/kenwell/archive/2010/06/25/118723.html</guid><wfw:comment>http://www.cppblog.com/kenwell/comments/118723.html</wfw:comment><comments>http://www.cppblog.com/kenwell/archive/2010/06/25/118723.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kenwell/comments/commentRss/118723.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kenwell/services/trackbacks/118723.html</trackback:ping><description><![CDATA[
<table cellspacing="0" cellpadding="0" style="word-wrap: break-word; empty-cells: show; border-collapse: collapse; line-height: normal; table-layout: fixed; margin-left: 1px; font-family: song, Verdana; font-size: 12px; width: 1066px; "><tbody style="word-wrap: break-word; line-height: normal; "><tr style="word-wrap: break-word; line-height: normal; "><td class="t_msgfont" id="postmessage_4976885" style="word-wrap: break-word; color: rgb(0, 0, 0); font: normal normal normal 12px/normal song, Verdana; line-height: 1.6em; font-size: 14px; ">几个知识点<br style="word-wrap: break-word; line-height: normal; "><font color="blue" style="word-wrap: break-word; line-height: normal; "><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">1.Bash在实现pipeline(管道|)时会发起两个sub<span href="tag.php?name=shell" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 0, 0); white-space: nowrap; ">shell</span>(子shell)来运行|两边的<span href="tag.php?name=%C3%FC%C1%EE" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 0, 0); white-space: nowrap; ">命令</span>，对于<span href="tag.php?name=%CF%B5%CD%B3" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 0, 0); white-space: nowrap; ">系统</span>来说就是发起两个childprocess(子进程）<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">2.fork是产生process的唯一途径，exec*是执行程序的唯一途径<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">3.子进程会完全复制父进程，除了$PID与$PPID<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">4.fork子进程时继承父进程的进程名，在exec*执行命令时才由exec*替换为子进程对应的命令，同一进程的命令名可以由一个个exec*任意多次的改变</strong></font><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">[注]<font color="green" style="word-wrap: break-word; line-height: normal; ">对于<span href="tag.php?name=linux" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 0, 0); white-space: nowrap; ">linux</span><span href="tag.php?name=%C6%BD%CC%A8" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 0, 0); white-space: nowrap; ">平台</span>，JB上就是这样的，其它平台不好发表意见，当然对于2中的两个唯一有一个例外，就是在kenerl&nbsp;&nbsp;init的初期;<br style="word-wrap: break-word; line-height: normal; ">暂时找不到相关参考，也没有功力读源码，所以此论是道听途说级别，错误之处请指出改正，如果没有改正的价值可一笑而过<br><br><span style="color: rgb(0, 0, 0); line-height: 22px; ">我觉得要先弄清楚sub shell的定义。<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">查了些资料，发现subshell的定义有些混乱。<br style="word-wrap: break-word; line-height: normal; ">bashMan:<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><div class="msgbody" style="word-wrap: break-word; overflow-x: hidden; overflow-y: hidden; width: 1066px; line-height: normal; "><div class="msgheader" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; border-left-color: rgb(0, 0, 0); font-weight: bold; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; color: rgb(0, 0, 0); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">QUOTE:</div><div class="msgborder" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-left-color: rgb(0, 0, 0); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">Each command in a pipeline is executed as a separate process (i.e., in a subshell).&nbsp;&nbsp;</div></div><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><div class="msgbody" style="word-wrap: break-word; overflow-x: hidden; overflow-y: hidden; width: 1066px; line-height: normal; "><div class="msgheader" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; border-left-color: rgb(0, 0, 0); font-weight: bold; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; color: rgb(0, 0, 0); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">QUOTE:</div><div class="msgborder" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-left-color: rgb(0, 0, 0); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">When a simple command other than a builtin or shell function is to be executed, it is invoked in a<br style="word-wrap: break-word; line-height: normal; ">separate execution environment that consists of the following. Unless otherwise noted, the values are<br style="word-wrap: break-word; line-height: normal; ">inherited from the shell.</div></div><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">这个separate execution是subshell吗？<br>A. 在当前shell执行外部命令，如shell&gt; date, 是fork+exec, 算不是subshell?&nbsp;<br style="word-wrap: break-word; line-height: normal; ">B. ()是fork一个child shell，该child再fork+exec来执行命令。这个subshell和A中的"subshell"显然是不同的。<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">UNIX: The Textbook, by Syed Mansoor Sarvar, Robert Koretsky and Syed Aqeel Sarvar中提到：<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><div class="msgbody" style="word-wrap: break-word; overflow-x: hidden; overflow-y: hidden; width: 1066px; line-height: normal; "><div class="msgheader" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; border-left-color: rgb(0, 0, 0); font-weight: bold; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; color: rgb(0, 0, 0); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">QUOTE:</div><div class="msgborder" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-left-color: rgb(0, 0, 0); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">A child shell is also called subshell</div></div><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">问题是fork+exec是fork一个child shell，然后在该child shell中exec.<br style="word-wrap: break-word; line-height: normal; ">而执行脚本(shell&gt;scriptname)时，是fort一个child shell A，该child shell A再fork一个child shell B, 在B中再exec.<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">那么child shell是指哪种情况？<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">UNIX at Fermilab中的Important UNIX Concepts:<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><div class="msgbody" style="word-wrap: break-word; overflow-x: hidden; overflow-y: hidden; width: 1066px; line-height: normal; "><div class="msgheader" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; border-left-color: rgb(0, 0, 0); font-weight: bold; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; color: rgb(0, 0, 0); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">QUOTE:</div><div class="msgborder" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-left-color: rgb(0, 0, 0); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">When you give the shell a command associated with a compiled executable or shell script, the shell<br style="word-wrap: break-word; line-height: normal; ">creates, or forks, a new process called a subshell.</div></div><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">外部命令也在subshell中执行。<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><div class="msgbody" style="word-wrap: break-word; overflow-x: hidden; overflow-y: hidden; width: 1066px; line-height: normal; "><div class="msgheader" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; border-left-color: rgb(0, 0, 0); font-weight: bold; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; color: rgb(0, 0, 0); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">QUOTE:</div><div class="msgborder" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-left-color: rgb(0, 0, 0); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">To execute most built-in commands, the shell forks a subshell which executes the command directly (no<br style="word-wrap: break-word; line-height: normal; ">exec system call). For the built-in commands cd, set, alias and source, the current shell executes the<br style="word-wrap: break-word; line-height: normal; ">command; no subshell is forked.</div></div><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">shell&gt; built-inCommands这样执行时，大部分内部命令也是在subshell中执行。<br style="word-wrap: break-word; line-height: normal; ">可见，UNIX at Fermilab认为fork 一个child shell就是subshell, 不管是fork-fork+exec, 还是 fork+exec。<br><br><span style="line-height: normal; font-size: 12px; "><table cellspacing="0" cellpadding="0" style="word-wrap: break-word; empty-cells: show; border-collapse: collapse; line-height: normal; table-layout: fixed; margin-left: 1px; width: 1066px; "><tbody style="word-wrap: break-word; line-height: normal; "><tr style="word-wrap: break-word; line-height: normal; "><td class="t_msgfont" id="postmessage_10708380" style="word-wrap: break-word; color: rgb(0, 0, 0); font: normal normal normal 12px/normal song, Verdana; line-height: 1.6em; font-size: 14px; ">我刚才又去翻了下ABS，定义与我的理解不一样<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; "><div class="msgbody" style="word-wrap: break-word; overflow-x: hidden; overflow-y: hidden; width: 1066px; line-height: normal; "><div class="msgheader" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; border-left-color: rgb(0, 0, 0); font-weight: bold; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; color: rgb(0, 0, 0); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">QUOTE:</div><div class="msgborder" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-left-color: rgb(0, 0, 0); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">A subshell is a separate instance of the command processor -- the shell that gives you the prompt at the<br style="word-wrap: break-word; line-height: normal; ">console or in an xterm window. Just as your commands are interpreted at the command line prompt, similarly<br style="word-wrap: break-word; line-height: normal; ">does a script batch-process a list of commands. Each shell script running is, in effect, a subprocess (child<br style="word-wrap: break-word; line-height: normal; ">process) of the parent shell.</div><span style="font-size: 12px; "><table cellspacing="0" cellpadding="0" style="word-wrap: break-word; empty-cells: show; border-collapse: collapse; line-height: normal; table-layout: fixed; margin-left: 1px; width: 1066px; "><tbody style="word-wrap: break-word; line-height: normal; "><tr style="word-wrap: break-word; line-height: normal; "><td class="t_msgfont" id="postmessage_10710881" style="word-wrap: break-word; color: rgb(0, 0, 0); font: normal normal normal 12px/normal song, Verdana; line-height: 1.6em; font-size: 14px; ">./script也是external_cmd的一种啊，都是fork-exec，至于external-cmd再作什么动作完全是external-cmd的</td></tr></tbody></table></span><div><img src="http://www.cppblog.com/images/cppblog_com/kenwell/20090615_cd6076dc3d1c9388f481pPz4AnaxYBiE.png" id="" width="936" height="187" vspace="0" hspace="0" border="" align="baseline" alt="" longdesc=""><br></div></div></td></tr></tbody></table></span></span></font></td></tr></tbody></table><img src ="http://www.cppblog.com/kenwell/aggbug/118723.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kenwell/" target="_blank">c++ 学习</a> 2010-06-25 16:35 <a href="http://www.cppblog.com/kenwell/archive/2010/06/25/118723.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>shell metacharacters 与IFS讨论</title><link>http://www.cppblog.com/kenwell/archive/2010/06/25/118721.html</link><dc:creator>c++ 学习</dc:creator><author>c++ 学习</author><pubDate>Fri, 25 Jun 2010 08:29:00 GMT</pubDate><guid>http://www.cppblog.com/kenwell/archive/2010/06/25/118721.html</guid><wfw:comment>http://www.cppblog.com/kenwell/comments/118721.html</wfw:comment><comments>http://www.cppblog.com/kenwell/archive/2010/06/25/118721.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kenwell/comments/commentRss/118721.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kenwell/services/trackbacks/118721.html</trackback:ping><description><![CDATA[<span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">good job!</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">總算有人看得懂了。</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">不過，要細說的話，要扯上 shell 在 interpret 一個 command line 時的 priority 。</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">基本上，其順序如下：</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">1，將 line 拆成 words （IFS很重要）</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">2，括展 alias</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">3，擴展 ｛ ｝</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">4，擴展 ~</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">5，擴展 $variable, $(command), `command`</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">6，重組再拆成 words</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">7，括展 wildcards</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">8，處理 I/O redirection</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">9，載入命令運行</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">如果大家有O'Reilly英文版的 Learning the Bash(2nd)的話，請多端詳p178的圖（細節略異）</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">回到LZ的問題，看上面 5 跟 6 的順序然後才是 9 。</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">也就是在 6 重組命令時 $A 已經完成替換，當時的 environment 是沒賦值，</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">因此重組後就是 A=B echo</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">然後在第 9 的步驟運行命令時， A=B 是給 echo 命令的 local environment，</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">不管是否 built-in command，都不影響當前的 shell （不同的 shell 在實作上或有差異）</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">所以第二行的 echo $A 也是得到沒賦值</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span>

<div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><span  style="line-height: normal; font-size: 12px; "><table cellspacing="0" cellpadding="0" style="word-wrap: break-word; empty-cells: show; border-collapse: collapse; line-height: normal; table-layout: fixed; margin-left: 1px; width: 1066px; "><tbody style="word-wrap: break-word; line-height: normal; "><tr style="word-wrap: break-word; line-height: normal; "><td class="t_msgfont" id="postmessage_10267043" style="word-wrap: break-word; color: rgb(0, 0, 0); font: normal normal normal 12px/normal song, Verdana; line-height: 1.6em; font-size: 14px; ">我通过eval说明赋值是成功的，而不是65楼所说的赋值不成功。<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">第一步使用 metacharacter，与IFS没有关系<br><br></td></tr></tbody></table></span></span></div><div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><span  style="line-height: normal; ">The following is a brief description of the shell's operation when it<br style="word-wrap: break-word; line-height: normal; ">reads and executes a command.&nbsp;&nbsp;Basically, the shell does the following:<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">&nbsp;&nbsp;1. Reads its input from a file (*note Shell Scripts::), from a string<br style="word-wrap: break-word; line-height: normal; ">&nbsp; &nbsp;&nbsp;&nbsp;supplied as an argument to the `-c' invocation option (*note<br style="word-wrap: break-word; line-height: normal; ">&nbsp; &nbsp;&nbsp;&nbsp;Invoking Bash::), or from the user's terminal.<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">&nbsp;&nbsp;2. Breaks the input into words and operators, obeying the quoting<br style="word-wrap: break-word; line-height: normal; ">&nbsp; &nbsp;&nbsp;&nbsp;rules described in *Note Quoting::.&nbsp;&nbsp;These tokens are separated by<br style="word-wrap: break-word; line-height: normal; ">&nbsp; &nbsp;&nbsp;&nbsp;`metacharacters'.&nbsp;&nbsp;Alias expansion is performed by this step<br style="word-wrap: break-word; line-height: normal; ">&nbsp; &nbsp;&nbsp;&nbsp;(*note Aliases::).</span></span></div><div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><span  style="line-height: normal; "><div class="msgheader" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; border-left-color: rgb(0, 0, 0); font-weight: bold; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; color: rgb(0, 0, 0); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">QUOTE:</div><div class="msgborder" style="word-wrap: break-word; margin-top: 0px; margin-right: 1em; margin-bottom: 0px; margin-left: 1em; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-left-color: rgb(0, 0, 0); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 244); overflow-x: hidden; overflow-y: hidden; width: 980px; line-height: normal; ">`IFS'<br style="word-wrap: break-word; line-height: normal; ">&nbsp; &nbsp;&nbsp;&nbsp;A list of characters that separate fields; used when the shell<br style="word-wrap: break-word; line-height: normal; ">&nbsp; &nbsp;&nbsp;&nbsp;splits words as part of expansion.</div></span></span></div><div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><span  style="line-height: normal; ">`metacharacter'<br style="word-wrap: break-word; line-height: normal; ">&nbsp; &nbsp;&nbsp;&nbsp;A character that, when unquoted, separates words.&nbsp;&nbsp;A metacharacter<br style="word-wrap: break-word; line-height: normal; ">&nbsp; &nbsp;&nbsp;&nbsp;is a `blank' or one of the following characters: `|', `&amp;', `;',<br style="word-wrap: break-word; line-height: normal; ">&nbsp; &nbsp;&nbsp;&nbsp;`(', `)', `&lt;', or `&gt;'.</span></span></div><div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><span  style="line-height: normal; "><span  style="line-height: 22px; ">8.05 命令行的评价（evaluation）<br style="word-wrap: break-word; line-height: normal; ">下面是C shell 解释命令行的顺序：<br style="word-wrap: break-word; line-height: normal; ">1. 历史替换<br style="word-wrap: break-word; line-height: normal; ">2. 分裂词（包括特殊字符）<br style="word-wrap: break-word; line-height: normal; ">3. 更新历史表<br style="word-wrap: break-word; line-height: normal; ">4. 解释单引号（'） 和 双引号（"）<br style="word-wrap: break-word; line-height: normal; ">5. 别名替换<br style="word-wrap: break-word; line-height: normal; ">6. 输入和输出的重定向（如 &gt;&nbsp;&nbsp;&lt; 和 |）<br style="word-wrap: break-word; line-height: normal; ">7. 变量替换<br style="word-wrap: break-word; line-height: normal; ">8. 命令替换<br style="word-wrap: break-word; line-height: normal; ">9. 文件名扩展<br style="word-wrap: break-word; line-height: normal; ">（Bourne shell 的解释顺序本质上是一样的，除了它不执行历史替换和别名替换之外）<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">所以<br style="word-wrap: break-word; line-height: normal; ">A=B&nbsp;&nbsp;echo&nbsp; &nbsp; $A<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">的执行过程应该是这样的：<br style="word-wrap: break-word; line-height: normal; ">1. 没有历史操作符， 因此不进行历史替换（Bourne shell 不执行这一步）<br style="word-wrap: break-word; line-height: normal; ">2. 分裂词，每碰到未加引号的空白字符就会产生一个新&#8220;词&#8221;。这些词是 A=B、echo、$A。<br style="word-wrap: break-word; line-height: normal; ">3. shell 将命令行放到历史列表中。（Bourne shell 不执行这一步）<br style="word-wrap: break-word; line-height: normal; ">4. 没有引号需要解释<br style="word-wrap: break-word; line-height: normal; ">5. 没有别名需要替换<br style="word-wrap: break-word; line-height: normal; ">6. 没有输入或输出重定向需要处理<br style="word-wrap: break-word; line-height: normal; ">7. shell注意到变量$A，并把它替换成空<br style="word-wrap: break-word; line-height: normal; ">8. shell寻找左单引号，执行左单引号中的任何命令，并且将命令的输出插入到命令行中。在本例中，没有这方面的事需要做。（如果左单引号内有通配符或者变量，那么在shell运行左单引号中的命令之前它们是不会被解释的）<br style="word-wrap: break-word; line-height: normal; ">9. shell寻找通配符。本例中没有，不需要处理<br style="word-wrap: break-word; line-height: normal; ">10. shell 执行 A=B， 执行 echo 。</span></span></span></div><div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><span  style="line-height: normal; "><span  style="line-height: 22px; ">8.05 命令行的评价（evaluation）<br style="word-wrap: break-word; line-height: normal; ">下面是C shell 解释命令行的顺序：<br style="word-wrap: break-word; line-height: normal; ">1. 历史替换<br style="word-wrap: break-word; line-height: normal; ">2. 分裂词（包括特殊字符）<br style="word-wrap: break-word; line-height: normal; ">3. 更新历史表<br style="word-wrap: break-word; line-height: normal; ">4. 解释单引号（'） 和 双引号（"）<br style="word-wrap: break-word; line-height: normal; ">5. 别名替换<br style="word-wrap: break-word; line-height: normal; ">6. 输入和输出的重定向（如 &gt;&nbsp;&nbsp;&lt; 和 |）<br style="word-wrap: break-word; line-height: normal; ">7. 变量替换<br style="word-wrap: break-word; line-height: normal; ">8. 命令替换<br style="word-wrap: break-word; line-height: normal; ">9. 文件名扩展<br style="word-wrap: break-word; line-height: normal; ">（Bourne shell 的解释顺序本质上是一样的，除了它不执行历史替换和别名替换之外）<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">所以<br style="word-wrap: break-word; line-height: normal; ">A=B&nbsp;&nbsp;echo&nbsp; &nbsp; $A<br style="word-wrap: break-word; line-height: normal; "><br style="word-wrap: break-word; line-height: normal; ">的执行过程应该是这样的：<br style="word-wrap: break-word; line-height: normal; ">1. 没有历史操作符， 因此不进行历史替换（Bourne shell 不执行这一步）<br style="word-wrap: break-word; line-height: normal; ">2. 分裂词，每碰到未加引号的空白字符就会产生一个新&#8220;词&#8221;。这些词是 A=B、echo、$A。<br style="word-wrap: break-word; line-height: normal; ">3. shell 将命令行放到历史列表中。（Bourne shell 不执行这一步）<br style="word-wrap: break-word; line-height: normal; ">4. 没有引号需要解释<br style="word-wrap: break-word; line-height: normal; ">5. 没有别名需要替换<br style="word-wrap: break-word; line-height: normal; ">6. 没有输入或输出重定向需要处理<br style="word-wrap: break-word; line-height: normal; ">7. shell注意到变量$A，并把它替换成空<br style="word-wrap: break-word; line-height: normal; ">8. shell寻找左单引号，执行左单引号中的任何命令，并且将命令的输出插入到命令行中。在本例中，没有这方面的事需要做。（如果左单引号内有通配符或者变量，那么在shell运行左单引号中的命令之前它们是不会被解释的）<br style="word-wrap: break-word; line-height: normal; ">9. shell寻找通配符。本例中没有，不需要处理<br style="word-wrap: break-word; line-height: normal; ">10. shell 执行 A=B， 执行 echo 。</span></span></span></div><div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><span  style="line-height: normal; "><span  style="line-height: 22px; "><br></span></span></span></div><img src ="http://www.cppblog.com/kenwell/aggbug/118721.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kenwell/" target="_blank">c++ 学习</a> 2010-06-25 16:29 <a href="http://www.cppblog.com/kenwell/archive/2010/06/25/118721.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>BASH 中的字符串处理</title><link>http://www.cppblog.com/kenwell/archive/2010/06/22/118487.html</link><dc:creator>c++ 学习</dc:creator><author>c++ 学习</author><pubDate>Tue, 22 Jun 2010 10:44:00 GMT</pubDate><guid>http://www.cppblog.com/kenwell/archive/2010/06/22/118487.html</guid><wfw:comment>http://www.cppblog.com/kenwell/comments/118487.html</wfw:comment><comments>http://www.cppblog.com/kenwell/archive/2010/06/22/118487.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kenwell/comments/commentRss/118487.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kenwell/services/trackbacks/118487.html</trackback:ping><description><![CDATA[<span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><div>原文地址：<a href="http://bbs.chinaunix.net/thread-201843-1-1.html">http://bbs.chinaunix.net/thread-201843-1-1.html</a></div>得到长度</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><div class="blockcode" style="word-wrap: break-word; line-height: normal; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 5px; padding-left: 10px; width: 586px; border-left-color: rgb(204, 204, 204); background-image: url(http://bbs.chinaunix.net/images/default/codebg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 247, 247); overflow-x: hidden; overflow-y: hidden; border-collapse: collapse; font-family: song, Verdana; font-size: 14px; background-position: 0px 0px; background-repeat: no-repeat repeat; "><div id="code0" style="word-wrap: break-word; line-height: normal; "><ol style="word-wrap: break-word; line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%x="abcd"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">#方法一<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr length $x<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">4<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; "># 方法二<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo ${#x}<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">4<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; "># 方法三<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr "$x" : ".*"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">4<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; "># expr 的帮助<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; "># STRING : REGEXP&nbsp; &nbsp;anchored pattern match of REGEXP in STRING</li></ol></div><em style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; margin-left: 43px; color: rgb(0, 0, 0); font-size: 12px; cursor: pointer; ">复制代码</em></div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">查找子串</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><div class="blockcode" style="word-wrap: break-word; line-height: normal; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 5px; padding-left: 10px; width: 586px; border-left-color: rgb(204, 204, 204); background-image: url(http://bbs.chinaunix.net/images/default/codebg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 247, 247); overflow-x: hidden; overflow-y: hidden; border-collapse: collapse; font-family: song, Verdana; font-size: 14px; background-position: 0px 0px; background-repeat: no-repeat repeat; "><div id="code1" style="word-wrap: break-word; line-height: normal; "><ol style="word-wrap: break-word; line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr index&nbsp;&nbsp;$x "b"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">2<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr index&nbsp;&nbsp;$x "a"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">1<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr index&nbsp;&nbsp;$x "b"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">2<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr index&nbsp;&nbsp;$x "c"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">3<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr index&nbsp;&nbsp;$x "d"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">4</li></ol></div><em style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; margin-left: 43px; color: rgb(0, 0, 0); font-size: 12px; cursor: pointer; ">复制代码</em></div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">得到子字符串</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><div class="blockcode" style="word-wrap: break-word; line-height: normal; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 5px; padding-left: 10px; width: 586px; border-left-color: rgb(204, 204, 204); background-image: url(http://bbs.chinaunix.net/images/default/codebg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 247, 247); overflow-x: hidden; overflow-y: hidden; border-collapse: collapse; font-family: song, Verdana; font-size: 14px; background-position: 0px 0px; background-repeat: no-repeat repeat; "><div id="code2" style="word-wrap: break-word; line-height: normal; "><ol style="word-wrap: break-word; line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; "># 方法一<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; "># expr &lt;string&gt; startpos length<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr substr "$x" 1 3<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">abc<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr substr "$x" 1 5<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">abcd<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr substr "$x" 2 5<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">bcd<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; "># 方法二<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; "># ${x:pos:lenght}<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo ${x:1}<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">bcd<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo ${x:2}<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">cd<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo ${x:0}<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">abcd<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo ${x:0:2}<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">ab<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%pos=1<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%len=2<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo ${x:$pos:$len}<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">bc</li></ol></div><em style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; margin-left: 43px; color: rgb(0, 0, 0); font-size: 12px; cursor: pointer; ">复制代码</em></div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">匹配正则表达式</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><div class="blockcode" style="word-wrap: break-word; line-height: normal; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 5px; padding-left: 10px; width: 586px; border-left-color: rgb(204, 204, 204); background-image: url(http://bbs.chinaunix.net/images/default/codebg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 247, 247); overflow-x: hidden; overflow-y: hidden; border-collapse: collapse; font-family: song, Verdana; font-size: 14px; background-position: 0px 0px; background-repeat: no-repeat repeat; "><div id="code3" style="word-wrap: break-word; line-height: normal; "><ol style="word-wrap: break-word; line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; "># 打印匹配长度<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr match $x "."<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">1<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr match $x "abc"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">3<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%expr match $x "bc"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">0</li></ol></div><em style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; margin-left: 43px; color: rgb(0, 0, 0); font-size: 12px; cursor: pointer; ">复制代码</em></div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">字符串的掐头去尾</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><div class="blockcode" style="word-wrap: break-word; line-height: normal; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 5px; padding-left: 10px; width: 586px; border-left-color: rgb(204, 204, 204); background-image: url(http://bbs.chinaunix.net/images/default/codebg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 247, 247); overflow-x: hidden; overflow-y: hidden; border-collapse: collapse; font-family: song, Verdana; font-size: 14px; background-position: 0px 0px; background-repeat: no-repeat repeat; "><div id="code4" style="word-wrap: break-word; line-height: normal; "><ol style="word-wrap: break-word; line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%x=aabbaarealwwvvww<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo "${x%w*w}"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">aabbaarealwwvv<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo "${x%%w*w}"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">aabbaareal<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo "${x##a*a}"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">lwwvvww<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo "${x#a*a}"<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">bbaarealwwvvww</li></ol></div><em style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; margin-left: 43px; color: rgb(0, 0, 0); font-size: 12px; cursor: pointer; ">复制代码</em></div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">其中 , # 表示掐头， 因为键盘上 # 在 $ 的左面。</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">其中 , % 表示%，&nbsp;&nbsp;因为键盘上 % 在 $ 的右面。</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">单个的表示最小匹配，双个表示最大匹配。</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">也就是说，当匹配的有多种</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><span href="tag.php?name=%B7%BD%B0%B8" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 0, 0); white-space: nowrap; ">方案</span></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">的时候，选择匹配的最大长度还是最小长度。</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">字符串的替换</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><div class="blockcode" style="word-wrap: break-word; line-height: normal; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 5px; padding-left: 10px; width: 586px; border-left-color: rgb(204, 204, 204); background-image: url(http://bbs.chinaunix.net/images/default/codebg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 247, 247); overflow-x: hidden; overflow-y: hidden; border-collapse: collapse; font-family: song, Verdana; font-size: 14px; background-position: 0px 0px; background-repeat: no-repeat repeat; "><div id="code5" style="word-wrap: break-word; line-height: normal; "><ol style="word-wrap: break-word; line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%x=abcdabcd<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo ${x/a/b} # 只替换一个<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">bbcdabcd<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">%echo ${x//a/b} # 替换所有<br style="word-wrap: break-word; line-height: normal; "></li><li style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; line-height: 1.8em; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, '&quot;Lucida Console&quot;', '&quot;Courier New&quot;', serif; font-size: 12px; ">bbcdbbcd</li></ol></div><em style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; margin-left: 43px; color: rgb(0, 0, 0); font-size: 12px; cursor: pointer; ">复制代码</em></div><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">不可以使用 regexp ， 只能用 * ? 的</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><span href="tag.php?name=%CE%C4%BC%FE" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 0, 0); white-space: nowrap; ">文件</span></span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">扩展方式。</span><span  style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; "></span>
<img src ="http://www.cppblog.com/kenwell/aggbug/118487.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kenwell/" target="_blank">c++ 学习</a> 2010-06-22 18:44 <a href="http://www.cppblog.com/kenwell/archive/2010/06/22/118487.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>