??xml version="1.0" encoding="utf-8" standalone="yes"?>精品一区二区久久久久久久网站,亚洲乱码日产精品a级毛片久久 ,国产精品久久久久9999http://m.shnenglu.com/kenwell/category/14098.html自己学习(fn)所?/description>zh-cnWed, 04 Aug 2010 12:12:21 GMTWed, 04 Aug 2010 12:12:21 GMT60shell 变量间接引用http://m.shnenglu.com/kenwell/archive/2010/08/02/121977.htmlc++ 学习(fn)c++ 学习(fn)Mon, 02 Aug 2010 08:46:00 GMThttp://m.shnenglu.com/kenwell/archive/2010/08/02/121977.htmlhttp://m.shnenglu.com/kenwell/comments/121977.htmlhttp://m.shnenglu.com/kenwell/archive/2010/08/02/121977.html#Feedback0http://m.shnenglu.com/kenwell/comments/commentRss/121977.htmlhttp://m.shnenglu.com/kenwell/services/trackbacks/121977.htmlq种使用间接引用的方法是一个小技? 如果W二个变量更改了(jin)它的? 那么W一个变?/div>
必须被适当的解除引?像上边的例子一?. q运的是, 在Bash版本2中引?/div>
?{!variable}形式使得使用间接引用更加直观?
假设一个变量的值是W二个变量的名字. 那么我们如何从第一个变量中取得W二个变量的值呢? 比如,
如果a=letter_of_alphabetq且letter_of_alphabet=z, 那么我们能够通过引用变量a来获得z? q确
实是可以做到? 它被UCؓ(f)间接引用. 它用eval var1=\$$var2q种不^常的形式.


c++ 学习(fn) 2010-08-02 16:46 发表评论
]]>Linux Shell Bash 正则表达式介l?/title><link>http://m.shnenglu.com/kenwell/archive/2010/06/30/119014.html</link><dc:creator>c++ 学习(fn)</dc:creator><author>c++ 学习(fn)</author><pubDate>Wed, 30 Jun 2010 14:15:00 GMT</pubDate><guid>http://m.shnenglu.com/kenwell/archive/2010/06/30/119014.html</guid><wfw:comment>http://m.shnenglu.com/kenwell/comments/119014.html</wfw:comment><comments>http://m.shnenglu.com/kenwell/archive/2010/06/30/119014.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/kenwell/comments/commentRss/119014.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kenwell/services/trackbacks/119014.html</trackback:ping><description><![CDATA[<p>正则表达式就是由一pdҎ(gu)字符l成的字W串, 其中每个Ҏ(gu)字符都被UCؓ(f)<em>元字W?/em>, q些<em>元字W?/em>q不表示为它们字面上的含? 而会(x)被解释ؓ(f)一些特定的含义. 具个例子, 比如引用W号, 可能是表示某h的演讲内? <em>同上</em>, 也可能表CZؓ(f)我们下面要讲到的符L(fng)?含义. 正则表达式其实是由普通字W和元字W共同组成的集合, q个集合用来匚w(或指?模式. </p> <p>一个正则表辑ּ?x)包含下列一Ҏ(gu)多项:</p><ul> <li> <p><em class="FIRSTTERM">一个字W集</em>. q里所指的字符集只包含普通字W? q些字符只表C它们的字面含义. 正则表达式的最单Ş式就?em>?/em>包含字符? 而不包含元字W? </p></li> <li> <p><em class="FIRSTTERM">?/em>. <em>?/em>指定?jin)正则表辑ּ所要匹配的文本在文本行中所处的位置. 比如, <span id="nlflxlz" class="TOKEN">^</span>, ?span class="TOKEN">$</span>是? </p></li> <li> <p><em class="FIRSTTERM">修饰W?/em>. 它们扩大或羃?yu)?<em>修改</em>)?jin)正则表辑ּ匚w文本的范? 修饰W包含星? 括号, 和反斜杠. </p></li></ul> <p>正则表达式最主要的目的就是用?<em class="FIRSTTERM">RE</em>)文本搜烦(ch)与字W串操作. (译者注: 以下正则表达式也?x)被UCؓ(f)<em>RE</em>.) RE能够<em class="FIRSTTERM">匚w</em>单个字符或者一个字W集 -- ? 一个字W串, 或者一个字W串的一部分. </p> <ul> <li> <p>星号 -- <span id="fpnbbdf" class="TOKEN">*</span> -- 用来匚w它前面字W的L多次, <em>包括0?/em>. </p> <p><span id="jjbxbnv" class="QUOTE">"1133*"</span>匚w<tt class="REPLACEABLE"><em>11 + 一个或多个3 + 也允许后边还有其他字W?/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 id="bnhbntl" class="TOKEN">.</span> -- 用于匚wL一个字W? 除了(jin)换行W? <a name="AEN13724"><span id="lfzbllh" class="footnote">[1]</span></a> </p> <p><span id="jrlfhfl" class="QUOTE">"13."</span> 匚w<tt class="REPLACEABLE"><em>13 + 臛_一个Q意字W?包括I格)</em></tt>: <tt class="REPLACEABLE"><em>1133</em></tt>, <tt class="REPLACEABLE"><em>11333</em></tt>, 但不能匹?tt class="REPLACEABLE"><em>13</em></tt> (因ؓ(f)~少"."所能匹配的臛_一个Q意字W?. </p></li> <li> <p>脱字W号 -- <span id="vxpbnbj" class="TOKEN">^</span> -- 匚w行首, 但是某些时候需要依赖上下文环境, 在RE? 有时候也表示对一个字W集取反. </p></li> <li> <p><a name="DOLLARSIGNREF"></a></p> <p>元W?-- <span id="jtxjbtr" class="TOKEN">$</span> -- 在RE中用来匹配行? </p> <p><span id="rblfzfn" class="QUOTE">"XXX$"</span> 匚w行尾?em>XXX</em>. </p> <p><span id="dffjtjz" class="QUOTE">"^$"</span> 匚wI. </p></li> <li> <p><a name="BRACKETSREF"></a></p> <p>中括?-- <span id="dpjtdtr" class="TOKEN">[...]</span> -- 在RE? 匹配中括号字符集中的某一个字W? </p> <p><span id="bvpjdjh" class="QUOTE">"[xyz]"</span> 会(x)匚w字符<tt class="REPLACEABLE"><em>x</em></tt>, <tt class="REPLACEABLE"><em>y</em></tt>, ?tt class="REPLACEABLE"><em>z</em></tt>. </p> <p><span id="hjlxjfv" class="QUOTE">"[c-n]"</span> 匚w字符<tt class="REPLACEABLE"><em>c</em></tt>到字W?tt class="REPLACEABLE"><em>n</em></tt>之间的Q意一个字W? </p> <p><span id="xzblnlr" class="QUOTE">"[B-Pk-y]"</span> 匚w?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>之间的Q意一个字W? </p> <p><span id="dnpzbrh" class="QUOTE">"[a-z0-9]"</span> 匚wL写字母或数? </p> <p><span id="rtlnzfd" class="QUOTE">"[^b-d]"</span> 会(x)匚w范围?tt class="REPLACEABLE"><em>b</em></tt>?tt class="REPLACEABLE"><em>d</em></tt><em>之外?/em>L一个字W? q就是?span class="TOKEN">^</span>对字W集取反的一个实? (好像在某些情况? <span id="vhtvpll" class="TOKEN">!</span>所表达的含?. </p> <p>多个中括号字符集组合? 能够匚w一般的单词或数? <span id="bbxhtbx" class="QUOTE">"[Yy][Ee][Ss]"</span>能够匚w<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 id="xtvfznl" class="QUOTE">"[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]"</span> 可以匚wC保?Social Security number). </p></li> <li> <p>反斜?-- <span id="dfhbftb" class="TOKEN">\</span> -- 用来<a >转义</a>某个Ҏ(gu)含义的字W? q意味着, q个Ҏ(gu)字符会(x)被解释ؓ(f)字面含义. </p> <p><span id="rjlxzxf" class="QUOTE">"\$"</span>会(x)被解释成字符<span id="bjvhbhx" class="QUOTE">"$"</span>, 而不是RE中匹配行Ҏ(gu)字符. 怼? <span id="rjvhrxp" class="QUOTE">"\\"</span>会(x)被解释ؓ(f)字符<span id="tfprtrp" class="QUOTE">"\"</span>. </p></li> <li> <p><a name="ANGLEBRAC"></a></p> <p><a >转义</a>?span class="QUOTE">"括?</span> -- <span id="ttvfjxn" class="TOKEN">\<...\></span> -- 用于匚w单词边界. </p> <p>括号必被转义才含有特D的含义, 否则它就表示括L(fng)字面含义. </p> <p><span id="vxhbdtp" class="QUOTE">"\<the\>"</span> 完整匚w单词<span id="nxrjndz" class="QUOTE">"the"</span>, 不会(x)匚w<span id="rlvzzxx" class="QUOTE">"them"</span>, <span id="btnzjzp" class="QUOTE">"there"</span>, <span id="hbtvpfn" class="QUOTE">"other"</span>, {等. </p> <p> </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 '\<the\>' 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 id="prvxhfl" 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 TEST FILE: tstfile # 不匹?<br> 2  # 不匹?<br> 3 Run grep "1133*" on this file. # 匚w.<br> 4  # 不匹?<br> 5  # 不匹?<br> 6 This line contains the number 113. # 匚w.<br> 7 This line contains the number 13. # 不匹?<br> 8 This line contains the number 133. # 不匹?<br> 9 This line contains the number 1133. # 匚w.<br> 10 This line contains the number 113312. # 匚w.<br> 11 This line contains the number 1112. # 不匹?<br> 12 This line contains the number 113312312. # 匚w.<br> 13 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. # 匚w.<br> This line contains the number 113. # 匚w.<br> This line contains the number 1133. # 匚w.<br> This line contains the number 113312. # 匚w.<br> This line contains the number 113312312. # 匚w. </samp><br> </pre></font></td></tr></tbody></table></div></td></tr></tbody></table> <ul> <li style="LIST-STYLE-TYPE: square"> <div id="jtxptrf" class="FORMALPARA"> <p><strong><a name="EXTREGEX"></a>扩展的正则表辑ּ. </strong>d?jin)一些额外的匚w字符到基本集合中. 用于<a >egrep</a>, <a >awk</a>, ?a >Perl</a>.</p></div></li> <li> <p><a name="QUEXREGEX"></a></p> <p>问号 -- <span id="dpjdfvl" class="TOKEN">?</span> -- 匚w它前面的字符, 但是只能匚w1ơ或0? 通常用来匚w单个字符. </p></li> <li> <p><a name="PLUSREF"></a></p> <p>加号 -- <span id="dxrtxll" class="TOKEN">+</span> -- 匚w它前面的字符, 能够匚w一ơ或多次. 与前面讲?span class="TOKEN">*</span>号作用类? 但是<em>不能</em>匚w0个字W的情况. </p> <table style="width: 558px; height: 209px; " border="0" bgcolor="#e0e0e0"> <tbody> <tr> <td><font color="#000000"><pre class="PROGRAMLISTING"> 1 # GNU版本的sed和awk能够使用"+",<br> 2 # 但是它需要被转义一? <br> 3 <br> 4 echo a111b | sed -ne '/a1\+b/p'<br> 5 echo a111b | grep 'a1\+b'<br> 6 echo a111b | gawk '/a1+b/'<br> 7 # 上边3句的作用相同. <br> 8 <br> 9 # 感谢, S.C.</pre></font></td></tr></tbody></table></li> <li> <p><a >转义</a><span id="lnpttth" class="QUOTE">"大括?</span> -- <span id="xzrvvvt" class="TOKEN">\{ \}</span> -- 在{义后的大括号中加上一个数? q个数字是它前面的RE所能匹配的ơ数. </p> <p>大括号必ȝq{? 否则, 大括号仅仅表C字面含? q种用法q不是基本RE集合中的一部分, 仅仅是个技巧而以. </p> <p><span id="hhtfhfv" class="QUOTE">"[0-9]\{5\}"</span> _匚w5个数?(所匚w的字W范围是0?). </p> <div id="llfhrrf" 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">"l典"</span>(非POSIX兼容)?a >awk</a>版本中正常运行的. 然? <strong class="COMMAND">gawk</strong>命o(h)中有一?code class="OPTION">--re-interval</code>选项, 使用q个选项允怋用大括号形式的RE?无需转义). </p> <p> </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> -- 括v一l正则表辑ּ. 当你想?a >expr</a>q行<a >子字W串提取(substring extraction)</a>的时? 圆括号就有用? 如果和下面要讲的<span id="rtfzrrf" class="QUOTE">"<span id="bvhjbbh" class="TOKEN">|</span>"</span>操作W结合? 也非常有? </p></li> <li> <p>竖线 -- <strong class="COMMAND">|</strong> -- 是RE中的<span id="tvfzdbz" class="QUOTE">"?</span>操作W? 使用它能够匹配一l可选字W中的Q意一? </p> <p> </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 id="blnxrhn" 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>一栯够支持扩展正则表辑ּ, 上边q部分就描述?jin)扩展正则表辑ּ? </p></td></tr></tbody></table></div> <ul> <li style="LIST-STYLE-TYPE: square"> <div id="ztnfhfd" class="FORMALPARA"> <p><strong><a name="POSIXREF"></a>POSIX字符c? </strong><kbd class="USERINPUT">[:class:]</kbd></p></div> <p>q是另外一U? 用于指定匚w字符范围的方? </p></li> <li> <p><kbd class="USERINPUT">[:alnum:]</kbd> 匚w字母和数? {h(hun)?kbd class="USERINPUT">A-Za-z0-9</kbd>. </p></li> <li> <p><kbd class="USERINPUT">[:alpha:]</kbd> 匚w字母. {h(hun)?kbd class="USERINPUT">A-Za-z</kbd>. </p></li> <li> <p><kbd class="USERINPUT">[:blank:]</kbd> 匚w一个空格或是一个制表符(tab). </p></li> <li> <p><kbd class="USERINPUT">[:cntrl:]</kbd> 匚w控制字符. </p></li> <li> <p><kbd class="USERINPUT">[:digit:]</kbd> 匚w(十进?数字. {h(hun)?kbd class="USERINPUT">0-9</kbd>. </p></li> <li> <p><kbd class="USERINPUT">[:graph:]</kbd> (可打印的囑Ş字符). 匚wASCII码D围在33 - 126之间的字W? 与下面所提到?kbd class="USERINPUT">[:print:]</kbd>cM, 但是不包括空格字W?I格字符的ASCII码是32). </p></li> <li> <p><kbd class="USERINPUT">[:lower:]</kbd> 匚w写字母. {h(hun)?kbd class="USERINPUT">a-z</kbd>. </p></li> <li> <p><kbd class="USERINPUT">[:print:]</kbd> (可打印的囑Ş字符). 匚wASCII码D围在32 - 126之间的字W? 与上边的<kbd class="USERINPUT">[:graph:]</kbd>cM, 但是包含I格. </p></li> <li> <p><kbd class="USERINPUT">[:space:]</kbd> 匚wI白字符(I格和水q_表符). </p></li> <li> <p><kbd class="USERINPUT">[:upper:]</kbd> 匚w大写字母. {h(hun)?kbd class="USERINPUT">A-Z</kbd>. </p></li> <li> <p><kbd class="USERINPUT">[:xdigit:]</kbd> 匚w16q制数字. {h(hun)?kbd class="USERINPUT">0-9A-Fa-f</kbd>. </p> <div id="fptvzxv" 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字符c通常都要用引h<a >双中括号</a>([[ ]])引v? </p> <p> </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>如果在一个受限的范围? q些字符cȝ臛_以用?a >通配(globbing)</a>? </p> <p> </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>如果想了(jin)解POSIX字符cd脚本中的使用情况, 请参?a >例子 12-18</a>?a >例子 12-19</a>. </p></td></tr></tbody></table></div></li></ul> <p><a >Sed</a>, <a >awk</a>, ?a >Perl</a>在脚本中一般都被用作过滤器, q些qo(h)器将?x)以RE为参? Ҏ(gu)件或者I/O进?qo(h)"或{? 请参?a >例子 A-12</a>?a >例子 A-17</a>, 来详l了(jin)解这U用? </p> <p>对于REq个复杂的主? 标准的参考材料是Friedl?em class="CITETITLE">Mastering Regular Expressions</em>. 由Dougherty和Robbins所~写?em class="CITETITLE">Sed & Awk</em>q本? 也对REq行?jin)清晰的? 如果惌得这些书的更多信? 请察?a ><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 name="FTN.AEN13724"><span id="fjlvhff" class="footnote">[1]</span></a></td> <td valign="top" width="95%" align="left"> <p>因ؓ(f)<a >sed</a>, <a >awk</a>, ?a >grep</a>通常用于处理单行, 但是不能匚w一个换行符. 如果你想处理多行输入的话, 那么你可以??来匹配换行符. </p> <table style="width: 520px; height: 532px; " border="0" bgcolor="#e0e0e0"> <tbody> <tr> <td><font color="#000000"><pre class="PROGRAMLISTING"> 1 #!/bin/bash<br> 2 <br> 3 sed -e 'N;s/.*/[&]/' << EOF # Here Document<br> 4 line1<br> 5 line2<br> 6 EOF<br> 7 # 输出:<br> 8 # [line1<br> 9 # line2]<br> 10 <br> 11 <br> 12 <br> 13 echo<br> 14 <br> 15 awk '{ $0=$1 "\n" $2; if (/line.1/) {print}}' << EOF<br> 16 line 1<br> 17 line 2<br> 18 EOF<br> 19 # 输出:<br> 20 # line<br> 21 # 1<br> 22 <br> 23 <br> 24 # 感谢, S.C.<br> 25 <br> 26 exit 0</pre></font></td></tr></tbody></table></td></tr></tbody></table><p> </p> <img src ="http://m.shnenglu.com/kenwell/aggbug/119014.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kenwell/" target="_blank">c++ 学习(fn)</a> 2010-06-30 22:15 <a href="http://m.shnenglu.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://m.shnenglu.com/kenwell/archive/2010/06/28/118870.html</link><dc:creator>c++ 学习(fn)</dc:creator><author>c++ 学习(fn)</author><pubDate>Mon, 28 Jun 2010 09:03:00 GMT</pubDate><guid>http://m.shnenglu.com/kenwell/archive/2010/06/28/118870.html</guid><wfw:comment>http://m.shnenglu.com/kenwell/comments/118870.html</wfw:comment><comments>http://m.shnenglu.com/kenwell/archive/2010/06/28/118870.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/kenwell/comments/commentRss/118870.html</wfw:commentRss><trackback:ping>http://m.shnenglu.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:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:black;mso-font-kerning:0pt"><span style="mso-list:Ignore">1.<span style="font:7.0pt "Times New Roman"">       </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:"Times New Roman","serif"; mso-fareast-font-family:?hu)?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:"Times New Roman","serif";mso-fareast-font-family:?hu)?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:"Times New Roman","serif"; mso-fareast-font-family:?hu)?color:black;mso-font-kerning:0pt">expr</span><span style="font-size:13.5pt;font-family:?hu)?mso-ascii-font-family:"Times New Roman"; mso-hansi-font-family:"Times New Roman";mso-bidi-font-family:"Times New Roman"; color:black;mso-font-kerning:0pt">只能用于一元操作符</span><span lang="EN-US" style="font-size:13.5pt;font-family:"Times New Roman","serif";mso-fareast-font-family: ?hu)?color:black;mso-font-kerning:0pt">,</span><span style="font-size:13.5pt; font-family:?hu)?mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";color:black; mso-font-kerning:0pt">不支持二元操作符</span><span lang="EN-US" style="font-size:12.0pt; font-family:?hu)?mso-bidi-font-family:?hu)?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:"Courier New";mso-fareast-font-family:?hu)?mso-bidi-font-family: "Times New Roman";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:"Courier New"; mso-fareast-font-family:?hu)?mso-bidi-font-family:"Times New Roman";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:"Courier New";mso-fareast-font-family: ?hu)?mso-bidi-font-family:"Times New Roman";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:"Courier New"; mso-fareast-font-family:?hu)?mso-bidi-font-family:"Times New Roman";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:"Courier New";mso-fareast-font-family:?hu)?mso-bidi-font-family: "Times New Roman";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:"Courier New"; mso-fareast-font-family:?hu)?mso-bidi-font-family:"Times New Roman";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:"Courier New";mso-fareast-font-family: ?hu)?mso-bidi-font-family:"Times New Roman";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:"Courier New"; mso-fareast-font-family:?hu)?mso-bidi-font-family:"Times New Roman";color:black; mso-font-kerning:0pt"> + </span><span lang="EN-US" style="font-size:8.0pt; mso-bidi-font-size:11.0pt;font-family:"Courier New";mso-fareast-font-family: ?hu)?mso-bidi-font-family:"Times New Roman";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:"Courier New";mso-fareast-font-family:?hu)?mso-bidi-font-family: "Times New Roman";color:maroon;mso-font-kerning:0pt">$x + 1</span><span style="font-size:8.0pt;mso-bidi-font-size:11.0pt;font-family:?hu)?mso-ascii-font-family: "Courier New";mso-hansi-font-family:"Courier New";mso-bidi-font-family:"Times New Roman"; color:maroon;mso-font-kerning:0pt">之间必须有空?/span><span lang="EN-US" style="font-size:13.5pt;font-family:"Times New Roman","serif";mso-fareast-font-family: ?hu)?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:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:black;mso-font-kerning:0pt"><span style="mso-list:Ignore">2.<span style="font:7.0pt "Times New Roman"">       </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:"Times New Roman","serif"; mso-fareast-font-family:?hu)?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:"Times New Roman","serif";mso-fareast-font-family:?hu)?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:?hu)? mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family: ?hu)?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:?hu)?mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:?hu)?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:?hu)? mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family: ?hu)?mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin">没有q回?/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:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:black;mso-font-kerning:0pt"><span style="mso-list:Ignore">3.<span style="font:7.0pt "Times New Roman"">       </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:?hu)?mso-ascii-font-family: "Times New Roman";mso-hansi-font-family:"Times New Roman";mso-bidi-font-family: "Times New Roman";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:"Times New Roman","serif";mso-fareast-font-family: ?hu)?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:?hu)?mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";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:"Times New Roman","serif"; mso-fareast-font-family:?hu)?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:?hu)?mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";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:"Times New Roman","serif"; mso-fareast-font-family:?hu)?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:?hu)?mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin; mso-fareast-font-family:?hu)?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:?hu)?mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin; mso-fareast-font-family:?hu)?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:?hu)?mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin; mso-fareast-font-family:?hu)?mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: Calibri;mso-hansi-theme-font:minor-latin">cM</span></p> <p class="MsoNormal"><span lang="EN-US">$(())</span><span style="font-family:?hu)? mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family: ?hu)?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:?hu)?mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:?hu)?mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">Q?/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> </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:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:black;mso-font-kerning:0pt"><span style="mso-list:Ignore">4.<span style="font:7.0pt "Times New Roman"">       </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:?hu)?mso-ascii-font-family: "Times New Roman";mso-hansi-font-family:"Times New Roman";mso-bidi-font-family: "Times New Roman";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:"Times New Roman","serif";mso-fareast-font-family: ?hu)?color:black;mso-font-kerning:0pt">$[<span style="mso-spacerun:yes">  </span>]</span></strong><strong style="mso-bidi-font-weight:normal"><span style="font-size:13.5pt;mso-bidi-font-size:11.0pt;font-family:?hu)?mso-ascii-font-family: "Times New Roman";mso-hansi-font-family:"Times New Roman";mso-bidi-font-family: "Times New Roman";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:"Times New Roman","serif";mso-fareast-font-family:?hu)?color:black; mso-font-kerning:0pt"><o:p></o:p></span></strong></p> <p class="MsoNormal"><span style="font-family:?hu)?mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:?hu)?mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">例如Q?/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">  </span>$[ n=$n+1 ](</span><span style="font-family:?hu)?mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:?hu)?mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">Q和</span><span lang="EN-US">$</span><span style="font-family:?hu)?mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:?hu)?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> </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:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:black;mso-font-kerning:0pt"><span style="mso-list:Ignore">5.<span style="font:7.0pt "Times New Roman"">       </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:?hu)?mso-ascii-font-family: "Times New Roman";mso-hansi-font-family:"Times New Roman";mso-bidi-font-family: "Times New Roman";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:"Times New Roman","serif";mso-fareast-font-family: ?hu)?color:black;mso-font-kerning:0pt">decalare<span style="mso-spacerun:yes">  </span></span></strong><strong style="mso-bidi-font-weight:normal"><span lang="EN-US" style="font-size:13.5pt;font-family:"Times New Roman","serif";mso-fareast-font-family: ?hu)?color:black;mso-font-kerning:0pt"><o:p></o:p></span></strong></p> <p class="MsoNormal"><span style="font-family:?hu)?mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:?hu)?mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">例子Q?/span></p> <p class="MsoNormal"><span lang="EN-US">decare –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://m.shnenglu.com/kenwell/aggbug/118870.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kenwell/" target="_blank">c++ 学习(fn)</a> 2010-06-28 17:03 <a href="http://m.shnenglu.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 q程替换Q?/title><link>http://m.shnenglu.com/kenwell/archive/2010/06/27/118826.html</link><dc:creator>c++ 学习(fn)</dc:creator><author>c++ 学习(fn)</author><pubDate>Sun, 27 Jun 2010 09:15:00 GMT</pubDate><guid>http://m.shnenglu.com/kenwell/archive/2010/06/27/118826.html</guid><wfw:comment>http://m.shnenglu.com/kenwell/comments/118826.html</wfw:comment><comments>http://m.shnenglu.com/kenwell/archive/2010/06/27/118826.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/kenwell/comments/commentRss/118826.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kenwell/services/trackbacks/118826.html</trackback:ping><description><![CDATA[<div class="vfzjfdj" 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 class="phbxpxd" id="content-area" style="padding-bottom: 20px; "><div class="nzrlhvl" id="node-1006985" class="node node-type-story" style="margin-top: 1em; margin-right: 1em; margin-bottom: 1em; margin-left: 1em; "><div id="vfhjlbz" class="node-inner"><div id="dnxztbz" class="meta" style="font-size: 0.9em; margin-top: 0.1em; "><div id="fpjtfnb" class="submitted">May 22, 2008  By <a title="View user profile." style="text-decoration: none; color: rgb(0, 51, 102); ">Mitch Frazier</a></div><div id="nfrdvtj" class="terms terms-inline" style="display: block; margin-top: 5px; "> 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 id="dhzvvtt" 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 rel="tag" title="" style="text-decoration: none; color: rgb(102, 102, 102); ">HOW-TOs</a></li></ul></div></div><div id="tnppbrp" 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 <a style="text-decoration: none; color: rgb(0, 51, 102); ">input/output redirection</a> the shell recognizes something called <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; "> <(list) or >(list) </pre>where each <em>list</em> 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 <em>name</em> 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 <tt>/dev/fd</tt> (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> </p><p>To substitute a command pipeline for an input file the syntax is:</p><pre style="overflow-x: auto; overflow-y: auto; "> command ... <(list) ... </pre>To substitute a command pipeline for an output file the syntax is:<pre style="overflow-x: auto; overflow-y: auto; "> command ... >(list) ... </pre><p> </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 <(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> </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 >tmp1 # sort b | uniq >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 <(sort a | uniq) <(sort b | uniq) a f g </pre><p> </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 <(sort a | uniq) <(sort b | uniq) fi </pre>The command <tt>set +o posix</tt> 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> </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>q程替换与命令替换很怼. 命o(h)替换把一个命令的l果赋值给一个变? 比如dir_contents=`ls -</p><p>al`或xref=$( grep word datafile). q程替换把一个进E的输出提供l另一个进E?换句话说, 它把</p><p>一个命令的l果发给?jin)另一个命?.</p><p>命o(h)替换的模?/p><p>用圆括号扩v来的命o(h)</p><p>>(command)</p><p><(command)</p><p>启动q程替换. 它?dev/fd/<n>文g圆括号中的q程处理l果发送给另一个进E? [1] (?/p><p>者注: 实际上现代的UNIXcL作系l提供的/dev/fd/n文g是与文g描述W相关的, 整数n指的?/p><p>是进E运行时对应数字的文件描q符)</p><p>?<"?>"与圆括号之间是没有空格的. 如果加了(jin)I格, ?x)生错?</p><p>bash$ echo >(true)</p><p>/dev/fd/63</p><p>bash$ echo <(true)</p><p>/dev/fd/63</p><p>Bash在两个文件描q符之间创徏?jin)一个管? --fIn和fOut--. true命o(h)的stdin被连接到fOut</p><p>(dup2(fOut, 0)), 然后Bash?dev/fd/fIn作ؓ(f)参数传给echo. 如果pȝ~Z/dev/fd/<n>文g, Bash?/p><p>使用临时文g. (感谢, S.C.)</p><p>q程替换可以比较两个不同命o(h)的输? 甚至能够比较同一个命令不同选项情况下的输出.</p><p>bash$ comm <(ls -l) <(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>使用q程替换来比较两个不同目录的内容(可以查看哪些文g名相? 哪些文g名不?:</p><p>1 diff <(ls $first_directory) <(ls $second_directory)</p><p>一些进E替换的其他用法与技?</p><p>1 cat <(ls -l)</p><p>2 # {h(hun)?ls -l | cat</p><p>3</p><p>4 sort -k 9 <(ls -l /bin) <(ls -l /usr/bin) <(ls -l /usr/X11R6/bin)</p><p>5 # 列出pȝ3个主?bin'目录中的所有文? q且按文件名q行排序.</p><p>6 # 注意??查一? 上面?个圆括号)明显不同的命令输Z递给'sort'.</p><p>7</p><p>8</p><p>9 diff <(command1) <(command2) # l出两个命o(h)输出的不同之?</p><p>10</p><p>11 tar cf >(bzip2 -c > file.tar.bz2) $directory_name</p><p>12 # 调用"tar cf /dev/fd/?? $directory_name", ?bzip2 -c > file.tar.bz2".</p><p>13 #</p><p>14 # 因ؓ(f)/dev/fd/<n>的系l属?</p><p>15 # 所以两个命令之间的道不必被命?</p><p>16 #</p><p>17 # q种效果可以被模拟出?</p><p>18 #</p><p>19 bzip2 -c < pipe > file.tar.bz2&</p><p>20 tar cf pipe $directory_name</p><p>21 rm pipe</p><p>22 # ?/p><p>23 exec 3>&1</p><p>24 tar cf /dev/fd/4 $directory_name 4>&1 >&3 3>&- | bzip2 -c > file.tar.bz2 3>&-</p><p>25 exec 3>&-</p><p>26</p><p>27</p><p>28 # 感谢, Stephane Chazelas</p><p>一个读者给我发?jin)一个有的例子, 是关于进E替换的, 如下.</p><p>1 # 摘自SuSE发行版中的代码片?</p><p>2</p><p>3 while read des what mask iface; do</p><p>4 # q里省略?jin)一些命?..</p><p>5 done < <(route -n)</p><p>6</p><p>7</p><p>8 # Z(jin)试? 我们让它做点?</p><p>9 while read des what mask iface; do</p><p>10 echo $des $what $mask $iface</p><p>11 done < <(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所l出的那? 一个更Ҏ(gu)理解的等价代码是:</p><p>21 route -n |</p><p>22 while read des what mask iface; do # 道的输?gu)赋值给?jin)变?</p><p>23 echo $des $what $mask $iface</p><p>24 done # q将产生Z上边相同的输?</p><p>25 # 然? Ulrich Gayer指出 . . .</p><p>26 #+ q个单的{h(hun)版本在while循环中用了(jin)一个子shell,</p><p>27 #+ 因此当管道结束后, 变量消׃(jin).</p><p>28</p><p>29</p><p>30</p><p>31 # 更进一? Filip Moritz解释?jin)上面两个例子之间存在一个细微的不同之处,</p><p>32 #+ 如下所C?</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 < <(route -n)</p><p>39 echo $y # $y 的gؓ(f)route -n的输?gu)?</p><p>40 )</p><p>41</p><p>42 # 一般来? (译者注: 原书作者在q里q未加注释符?#", 应该是笔?</p><p>43 (</p><p>44 : | x=x</p><p>45 # 看上L启动?jin)一个子shell</p><p>46 : | ( x=x )</p><p>47 # ?/p><p>48 x=x < <(:)</p><p>49 # 其实不是</p><p>50 )</p><p>51</p><p>52 # 当你要解析csv或类g西的时侯, q非常有?</p><p>53 # 事实? q就是SuSE的这个代码片断所要实现的功能.</p><p>注意事项</p><p>[1] q与命名道(临时文g)h相同的作? q且, 事实? 命名道也被同时使用在进E?/p><p>替换?</p></p></div></div></div></div><img src ="http://m.shnenglu.com/kenwell/aggbug/118826.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kenwell/" target="_blank">c++ 学习(fn)</a> 2010-06-27 17:15 <a href="http://m.shnenglu.com/kenwell/archive/2010/06/27/118826.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于bash的管道与q程的几个知识点http://m.shnenglu.com/kenwell/archive/2010/06/25/118723.htmlc++ 学习(fn)c++ 学习(fn)Fri, 25 Jun 2010 08:35:00 GMThttp://m.shnenglu.com/kenwell/archive/2010/06/25/118723.htmlhttp://m.shnenglu.com/kenwell/comments/118723.htmlhttp://m.shnenglu.com/kenwell/archive/2010/06/25/118723.html#Feedback0http://m.shnenglu.com/kenwell/comments/commentRss/118723.htmlhttp://m.shnenglu.com/kenwell/services/trackbacks/118723.html几个知识?br style="word-wrap: break-word; line-height: normal; ">1.Bash在实现pipeline(道|)时会(x)发v两个subshell(子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; ">命o(h)Q对?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; ">pȝ来说是发v两个childprocess(子进E)(j)

2.fork是生process的唯一途径Qexec*是执行程序的唯一途径

3.子进E会(x)完全复制父进E,除了(jin)$PID?PPID

4.fork子进E时l承父进E的q程名,在exec*执行命o(h)时才由exec*替换为子q程对应的命令,同一q程的命令名可以׃个个exec*L多次的改?/strong>



[注]对于linuxq_QJB上就是这L(fng)Q其它^C好发表意见,当然对于2中的两个唯一有一个例外,是在kenerl  init的初?
暂时找不到相兛_考,也没有功力读源码Q所以此论是道听途说U别Q错误之处请指出Ҏ(gu)Q如果没有改正的价值可一W而过

我觉得要先弄清楚sub shell的定义?br style="word-wrap: break-word; line-height: normal; ">
查了(jin)些资料,发现subshell的定义有些؜乱?br style="word-wrap: break-word; line-height: normal; ">bashMan:



QUOTE:
Each command in a pipeline is executed as a separate process (i.e., in a subshell).  




QUOTE:
When a simple command other than a builtin or shell function is to be executed, it is invoked in a
separate execution environment that consists of the following. Unless otherwise noted, the values are
inherited from the shell.



q个separate execution是subshell吗?
A. 在当前shell执行外部命o(h)Q如shell> date, 是fork+exec, 不是subshell? 
B. ()是fork一个child shellQ该child再fork+exec来执行命令。这个subshell和A中的"subshell"昄是不同的?br style="word-wrap: break-word; line-height: normal; ">
UNIX: The Textbook, by Syed Mansoor Sarvar, Robert Koretsky and Syed Aqeel Sarvar中提刎ͼ(x)


QUOTE:
A child shell is also called subshell


问题是fork+exec是fork一个child shellQ然后在该child shell中exec.
而执行脚?shell>scriptname)Ӟ是fort一个child shell AQ该child shell A再fork一个child shell B, 在B中再exec.

那么child shell是指哪种情况Q?br style="word-wrap: break-word; line-height: normal; ">


UNIX at Fermilab中的Important UNIX Concepts:



QUOTE:
When you give the shell a command associated with a compiled executable or shell script, the shell
creates, or forks, a new process called a subshell.


外部命o(h)也在subshell中执行?br style="word-wrap: break-word; line-height: normal; ">


QUOTE:
To execute most built-in commands, the shell forks a subshell which executes the command directly (no
exec system call). For the built-in commands cd, set, alias and source, the current shell executes the
command; no subshell is forked.



shell> built-inCommandsq样执行Ӟ大部分内部命令也是在subshell中执行?br style="word-wrap: break-word; line-height: normal; ">可见QUNIX at Fermilab认ؓ(f)fork 一个child shell是subshell, 不管是fork-fork+exec, q是 fork+exec?br>
我刚才又ȝ?jin)下ABSQ定义与我的理解不一?br style="word-wrap: break-word; line-height: normal; ">

QUOTE:
A subshell is a separate instance of the command processor -- the shell that gives you the prompt at the
console or in an xterm window. Just as your commands are interpreted at the command line prompt, similarly
does a script batch-process a list of commands. Each shell script running is, in effect, a subprocess (child
process) of the parent shell.
./script也是external_cmd的一U啊Q都是fork-execQ至于external-cmd再作什么动作完全是external-cmd?/td>



c++ 学习(fn) 2010-06-25 16:35 发表评论
]]>
shell metacharacters 与IFS讨论http://m.shnenglu.com/kenwell/archive/2010/06/25/118721.htmlc++ 学习(fn)c++ 学习(fn)Fri, 25 Jun 2010 08:29:00 GMThttp://m.shnenglu.com/kenwell/archive/2010/06/25/118721.htmlhttp://m.shnenglu.com/kenwell/comments/118721.htmlhttp://m.shnenglu.com/kenwell/archive/2010/06/25/118721.html#Feedback0http://m.shnenglu.com/kenwell/comments/commentRss/118721.htmlhttp://m.shnenglu.com/kenwell/services/trackbacks/118721.htmlgood job!
^算有h看得懂了(jin)?/span>

不過Q要細說的話Q要扯上 shell ?interpret 一?command line 時的 priority ?/span>
基本上,光序如下:(x)
1Q將 line 拆成 words QIFS很重要)(j)
2Q括?alias
3Q擴???/span>
4Q擴?~
5Q擴?$variable, $(command), `command`
6Q重i再拆成 words
7Q括?wildcards
8Q處?I/O redirection
9Q載(j)入命令運?/span>
如果大家有O'Reilly英文版的 Learning the Bash(2nd)的話Q請多端詳p178的圖Q細略異Q?/span>

回到LZ的問,看上?5 ?6 的順序然後才?9 ?/span>
也就是在 6 重組命o(h)?$A 已經完成替換Q當時的 environment 是沒賦|
因此重組後就?A=B echo
然後在第 9 的步驟運行命令時Q?A=B 是 echo 命o(h)?local environmentQ?/span>
不管是否 built-in commandQ都不媄(jing)響當前的 shell Q不同的 shell 在實作上或有差異Q?/span>
所以第二行?echo $A 也是得到沒c?/span>
我通过eval说明赋值是成功的,而不?5楼所说的赋g成功?br style="word-wrap: break-word; line-height: normal; ">
W一步?metacharacterQ与IFS没有关系

The following is a brief description of the shell's operation when it
reads and executes a command.  Basically, the shell does the following:

  1. Reads its input from a file (*note Shell Scripts::), from a string
     supplied as an argument to the `-c' invocation option (*note
     Invoking Bash::), or from the user's terminal.

  2. Breaks the input into words and operators, obeying the quoting
     rules described in *Note Quoting::.  These tokens are separated by
     `metacharacters'.  Alias expansion is performed by this step
     (*note Aliases::).
QUOTE:
`IFS'
     A list of characters that separate fields; used when the shell
     splits words as part of expansion.
`metacharacter'
     A character that, when unquoted, separates words.  A metacharacter
     is a `blank' or one of the following characters: `|', `&', `;',
     `(', `)', `<', or `>'.
8.05 命o(h)行的评h(hun)QevaluationQ?br style="word-wrap: break-word; line-height: normal; ">下面是C shell 解释命o(h)行的序Q?br style="word-wrap: break-word; line-height: normal; ">1. 历史替换
2. 分裂词(包括Ҏ(gu)字符Q?br style="word-wrap: break-word; line-height: normal; ">3. 更新历史?br style="word-wrap: break-word; line-height: normal; ">4. 解释单引P'Q??双引P"Q?br style="word-wrap: break-word; line-height: normal; ">5. 别名替换
6. 输入和输出的重定向(?>  < ?|Q?br style="word-wrap: break-word; line-height: normal; ">7. 变量替换
8. 命o(h)替换
9. 文g名扩?br style="word-wrap: break-word; line-height: normal; ">QBourne shell 的解释顺序本质上是一L(fng)Q除?jin)它不执行历史替换和别名替换之外Q?br style="word-wrap: break-word; line-height: normal; ">
所?br style="word-wrap: break-word; line-height: normal; ">A=B  echo    $A

的执行过E应该是q样的:(x)
1. 没有历史操作W, 因此不进行历史替换(Bourne shell 不执行这一步)(j)
2. 分裂词,每碰到未加引L(fng)I白字符׃(x)产生一个新“?#8221;。这些词?A=B、echo?A?br style="word-wrap: break-word; line-height: normal; ">3. shell 命令行攑ֈ历史列表中。(Bourne shell 不执行这一步)(j)
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注意到变?AQƈ把它替换成空
8. shellL左单引号Q执行左单引号中的Q何命令,q且命令的输出插入到命令行中。在本例中,没有q方面的事需要做。(如果左单引号内有通配W或者变量,那么在shellq行左单引号中的命o(h)之前它们是不?x)被解释的?j)
9. shellL通配W。本例中没有Q不需要处?br style="word-wrap: break-word; line-height: normal; ">10. shell 执行 A=BQ?执行 echo ?/span>
8.05 命o(h)行的评h(hun)QevaluationQ?br style="word-wrap: break-word; line-height: normal; ">下面是C shell 解释命o(h)行的序Q?br style="word-wrap: break-word; line-height: normal; ">1. 历史替换
2. 分裂词(包括Ҏ(gu)字符Q?br style="word-wrap: break-word; line-height: normal; ">3. 更新历史?br style="word-wrap: break-word; line-height: normal; ">4. 解释单引P'Q??双引P"Q?br style="word-wrap: break-word; line-height: normal; ">5. 别名替换
6. 输入和输出的重定向(?>  < ?|Q?br style="word-wrap: break-word; line-height: normal; ">7. 变量替换
8. 命o(h)替换
9. 文g名扩?br style="word-wrap: break-word; line-height: normal; ">QBourne shell 的解释顺序本质上是一L(fng)Q除?jin)它不执行历史替换和别名替换之外Q?br style="word-wrap: break-word; line-height: normal; ">
所?br style="word-wrap: break-word; line-height: normal; ">A=B  echo    $A

的执行过E应该是q样的:(x)
1. 没有历史操作W, 因此不进行历史替换(Bourne shell 不执行这一步)(j)
2. 分裂词,每碰到未加引L(fng)I白字符׃(x)产生一个新“?#8221;。这些词?A=B、echo?A?br style="word-wrap: break-word; line-height: normal; ">3. shell 命令行攑ֈ历史列表中。(Bourne shell 不执行这一步)(j)
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注意到变?AQƈ把它替换成空
8. shellL左单引号Q执行左单引号中的Q何命令,q且命令的输出插入到命令行中。在本例中,没有q方面的事需要做。(如果左单引号内有通配W或者变量,那么在shellq行左单引号中的命o(h)之前它们是不?x)被解释的?j)
9. shellL通配W。本例中没有Q不需要处?br style="word-wrap: break-word; line-height: normal; ">10. shell 执行 A=BQ?执行 echo ?/span>



c++ 学习(fn) 2010-06-25 16:29 发表评论
]]>
BASH 中的字符串处?/title><link>http://m.shnenglu.com/kenwell/archive/2010/06/22/118487.html</link><dc:creator>c++ 学习(fn)</dc:creator><author>c++ 学习(fn)</author><pubDate>Tue, 22 Jun 2010 10:44:00 GMT</pubDate><guid>http://m.shnenglu.com/kenwell/archive/2010/06/22/118487.html</guid><wfw:comment>http://m.shnenglu.com/kenwell/comments/118487.html</wfw:comment><comments>http://m.shnenglu.com/kenwell/archive/2010/06/22/118487.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/kenwell/comments/commentRss/118487.html</wfw:commentRss><trackback:ping>http://m.shnenglu.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>原文地址Q?a >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 id="zrtdfdd" 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 class="tvzbdth" 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; ">#Ҏ(gu)一<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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; "># Ҏ(gu)?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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; "># Ҏ(gu)?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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; "># STRING : REGEXP   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 id="bvxtdtj" 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 class="hlfpthx" 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; ">%expr index  $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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; ">%expr index  $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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; ">%expr index  $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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; ">%expr index  $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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; ">%expr index  $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, '"Lucida Console"', '"Courier New"', 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; ">得到子字W串</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 id="dfjlnbz" 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 class="tlxhlzx" 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; "># Ҏ(gu)一<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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; "># expr <string> 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; "># Ҏ(gu)?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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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; ">匚w正则表达?/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 id="nzzdxvj" 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 class="vtxhtrp" 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, '"Lucida Console"', '"Courier New"', serif; font-size: 12px; "># 打印匚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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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; ">字符串的掐头d</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 id="fxptvbj" 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 class="fdnhrhx" 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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; ">其中 , # 表示掐头Q?因ؓ(f)键盘?sh)?# ?$ 的左面?/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; ">其中 , % 表示%Q?nbsp; 因ؓ(f)键盘?sh)?% ?$ 的右面?/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; ">单个的表C最匹配,双个表示最大匹配?/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; ">也就是说Q当匚w的有多种</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; ">Ҏ(gu)</span></span><span style="border-collapse: collapse; font-family: song, Verdana; font-size: 14px; line-height: 22px; ">的时候,选择匚w的最大长度还是最长度?/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 id="rhrtdbr" 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 class="fdxpjhh" 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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, '"Lucida Console"', '"Courier New"', 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 Q?只能?* ? ?/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; ">文g</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://m.shnenglu.com/kenwell/aggbug/118487.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kenwell/" target="_blank">c++ 学习(fn)</a> 2010-06-22 18:44 <a href="http://m.shnenglu.com/kenwell/archive/2010/06/22/118487.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://m.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.printinginfo.com.cn" target="_blank">һһþþƷۺ</a>| <a href="http://www.xhlwd.cn" target="_blank">ۿþ</a>| <a href="http://www.qhsn.net.cn" target="_blank">þAVĻ</a>| <a href="http://www.ejyp.cn" target="_blank">þþþþþþòҰ߳</a>| <a href="http://www.dztd.gd.cn" target="_blank">һɫþ99һۺ</a>| <a href="http://www.r97n59.cn" target="_blank">ƷۺרƬþþ</a>| <a href="http://www.talkvo.cn" target="_blank">91޹˾þþƷ</a>| <a href="http://www.floodlighting.cn" target="_blank">պþþþĻ</a>| <a href="http://www.f7799.cn" target="_blank">99þþþƷѹۿ</a>| <a href="http://www.ikdianying.cn" target="_blank">þһѲ</a>| <a href="http://www.bilili.com.cn" target="_blank">999þþѾƷ</a>| <a href="http://www.czb668.cn" target="_blank">Ժձһձþ </a>| <a href="http://www.vufh.cn" target="_blank">þùҹAVӰԺ</a>| <a href="http://www.ltak.cn" target="_blank">޾þһ</a>| <a href="http://www.jxsrgh.com.cn" target="_blank">ھƷŷþþƷ</a>| <a href="http://www.710p.cn" target="_blank">þùɫavѿ</a>| <a href="http://www.111net.org.cn" target="_blank">ŮƷþþ</a>| <a href="http://www.ccguofeng.cn" target="_blank">ҹþþƷ</a>| <a href="http://www.antsgogo.cn" target="_blank">ŷƷþø</a>| <a href="http://www.gzkyzc.com.cn" target="_blank">޹˾þۺһ</a>| <a href="http://www.whnnmj.cn" target="_blank">þŷƷ</a>| <a href="http://www.shuffley.cn" target="_blank">޵һƷƷþ</a>| <a href="http://www.modellesson.cn" target="_blank">Ʒþþþһ</a>| <a href="http://www.uzxin.cn" target="_blank">ƷŮͬþþþõӰԺ</a>| <a href="http://www.paper51.cn" target="_blank">Ʒþþþþþù˽ </a>| <a href="http://www.legxcn.cn" target="_blank">ŷҹAŴƬþ</a>| <a href="http://www.hilxb.cn" target="_blank">Ʒһþþþþþվ</a>| <a href="http://www.sifaguojinb.cn" target="_blank">þþþŮAAƬ</a>| <a href="http://www.kiterunner.com.cn" target="_blank">AVþ</a>| <a href="http://www.ndj2.cn" target="_blank">þþ</a>| <a href="http://www.peizis.cn" target="_blank">޹뾫ƷŮ˾þþò </a>| <a href="http://www.ytmsw.cn" target="_blank">þþWWW</a>| <a href="http://www.better-led.cn" target="_blank">һһþaþþƷۺ </a>| <a href="http://www.n24657.cn" target="_blank">99ƷȾþ޶ </a>| <a href="http://www.mtdo.cn" target="_blank">Ʒһþ</a>| <a href="http://www.top119.cn" target="_blank">һһþۺϺݺ</a>| <a href="http://www.txt115.cn" target="_blank">18ƾþþAAAƬ</a>| <a href="http://www.iptid.com.cn" target="_blank">ŷ˼Ծþ</a>| <a href="http://www.co1txk.cn" target="_blank">˾þ</a>| <a href="http://www.khdv.cn" target="_blank">AVһȾþ</a>| <a href="http://www.shiweey.cn" target="_blank">ҹҹݺݾþAV</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>