锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲欧美精品在线,欧美一级播放,99国产精品久久久久老师http://m.shnenglu.com/kenwell/鑷繁瀛︿範鎵鐢?/description>zh-cnMon, 29 Sep 2025 14:37:05 GMTMon, 29 Sep 2025 14:37:05 GMT60宸ユ鍠勫叾浜嬪繀鍏堝埄鍏跺櫒--鎵撻爒im-cscope/ctags宸ュ叿閾?杞澆錛?/title><link>http://m.shnenglu.com/kenwell/archive/2010/08/21/124226.html</link><dc:creator>c++ 瀛︿範</dc:creator><author>c++ 瀛︿範</author><pubDate>Sat, 21 Aug 2010 14:28:00 GMT</pubDate><guid>http://m.shnenglu.com/kenwell/archive/2010/08/21/124226.html</guid><wfw:comment>http://m.shnenglu.com/kenwell/comments/124226.html</wfw:comment><comments>http://m.shnenglu.com/kenwell/archive/2010/08/21/124226.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/kenwell/comments/commentRss/124226.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kenwell/services/trackbacks/124226.html</trackback:ping><description><![CDATA[<p>Source Insight鐨勫己澶х殑浠g爜鍒嗘瀽鍔熻兘璁╂墍鏈墂indows涓嬬殑浼楃敓鍙楃泭鑿叉祬銆?/p> <p>鑰孲ource insight鐨勪環鏍煎嵆浣挎槸闈㈠Windows Vista涔熶笉閫炲銆傚樋鍢褲備笢瑗挎槸濂戒笢瑗褲?/p> <p>涓漢璁や負瀹冧篃瀵瑰緱璧瘋繖涓環鏍箋傚彲鎯滄病綾熾傜敤涓嶈搗鍛銆?/p> <p>鍜嬪姙鍛€傜敤vim錛宑scope鎵撻犱竴涓厤璐圭殑鍚с?br></p> <p><br></p> <p>1瀹夎cscope</p> <p>cscope鐨勭紪璇戝拰瀹夎娌℃湁鐗瑰埆涔嬪錛?/configure - make - make install鍗沖彲銆?br> 瀹夎漿瀹屾瘯鍚庡厛闃呰璇存槑: vi /usr/share/vim/vim63/doc/if_cscop.txt.gz<br> 緗戜笂涔熸湁涓枃鐗堟湰錛歨ttp://vcd.gro.clinux.org/doc/if_cscop.html<br> 鍦╲im涓嬌鐢ㄥ茍涓嶉渶瑕佽繘琛屽お澶氱殑璁劇疆錛屼笉榪囬鍏坴im緙栬瘧鏃跺繀欏誨姞鍏ヤ簡cscope鐨勬敮鎸?br> <br> $ vim --version | grep cscope<br> +cryptv +cscope +dialog_con +diff +digraphs -dnd -ebcdic +emacs_tags +eval<br> <br> <br> 鍡紝鎴戠敤鐨勮繖涓増鏈殑vim鏄敮鎸乧scope鐨勩?br> </p> <p>鎸?鐓im閲宑scope鐨勫弬鑰冩墜鍐?鍦╲im涓墽琛?:help cscope"鍛戒護)錛屾妸cscope鍔熻兘鍔犲埌.vimrc閲屽悗(闇瑕佷綘鐨剉im鍦ㄧ紪璇戞椂閫夋嫨浜?--enable-cscope"閫夐」錛屽惁鍒欎綘闇瑕侀噸鏂? 緙栬瘧vim)錛岄厤緗氨綆楀畬鎴愪簡銆傜劧鍚庣敤涓嬮潰鐨勫懡浠ょ敓鎴愪唬鐮佺殑絎﹀彿绱㈠紩鏂囦歡錛?br> <br> </p> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 50%; -moz-background-size: auto auto; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"> <div><span style="color: #000000;">    <span style="color: #0000ff;">cscope</span> -Rbkq</span></div> </div> <br> 榪欎釜鍛戒護浼氱敓鎴愪笁涓枃浠訛細cscope.out, cscope.in.out, cscope.po.out銆?br> 鍏朵腑cscope.out鏄熀鏈殑絎﹀彿绱㈠紩錛屽悗涓や釜鏂囦歡鏄嬌鐢?-q"閫夐」鐢熸垚鐨勶紝鍙互鍔犲揩cscope鐨勭儲寮曢熷害銆?br> 涓婇潰鎵鐢ㄥ埌鐨勫懡浠ゅ弬鏁幫紝鍚箟濡備笅錛?br> <br> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 50%; -moz-background-size: auto auto; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"> <div><img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top"><span style="color: #000000;"><span style="color: #0000ff;">-R</span>: 鍦ㄧ敓鎴愮儲寮曟枃浠舵椂錛屾悳绱㈠瓙鐩綍鏍戜腑鐨勪唬鐮?br> <img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top"><span style="color: #0000ff;">-b</span>: 鍙敓鎴愮儲寮曟枃浠訛紝涓嶈繘鍏scope鐨勭晫闈?br> <img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top"><span style="color: #0000ff;">-k</span>: 鍦ㄧ敓鎴愮儲寮曟枃浠舵椂錛屼笉鎼滅儲</span><span style="color: #000000;">/</span><span style="color: #000000;">usr</span><span style="color: #000000;">/</span><span style="color: #000000;">include鐩綍<br> <img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top"><span style="color: #0000ff;">-q</span>: 鐢熸垚cscope</span><span style="color: #000000;">.</span><span style="color: #000000;">in</span><span style="color: #000000;">.</span><span style="color: #000000;">out鍜宑scope</span><span style="color: #000000;">.</span><span style="color: #000000;">po</span><span style="color: #000000;">.</span><span style="color: #000000;">out鏂囦歡錛屽姞蹇玞scope鐨勭儲寮曢熷害</span></div> </div> <br> <br> 鎺ヤ笅鏉ワ紝灝卞彲浠ュ湪vim閲岃浠g爜浜嗐?br> 涓? 榪囧湪浣跨敤榪囩▼涓紝鍙戠幇鏃犳硶鎵懼埌C++鐨勭被銆佸嚱鏁板畾涔夈佽皟鐢ㄥ叧緋匯備粩緇嗛槄璇諱簡cscope鐨勬墜鍐屽悗鍙戠幇錛屽師鏉scope鍦ㄤ駭鐢熺儲寮曟枃浠舵椂錛屽彧鎼滅儲綾誨瀷涓? C, lex鍜寉acc鐨勬枃浠?鍚庣紑鍚嶄負.c, .h, .l, .y)錛孋++鐨勬枃浠舵牴鏈病鏈夌敓鎴愮儲寮曘備笉榪囨寜鐓ф墜鍐屼笂鐨勮鏄庯紝cscope鏀寔c++鍜孞ava璇█鐨勬枃浠躲?br> 浜庢槸鎸夌収cscope鎵嬪唽涓婃彁渚涚殑鏂規硶錛屽厛浜х敓涓涓枃浠跺垪琛紝鐒跺悗璁ヽscope涓鴻繖涓垪琛ㄤ腑鐨勬瘡涓枃浠墮兘鐢熸垚绱㈠紩銆?br> 涓轟簡鏂逛究浣跨敤錛岀紪鍐欎簡涓嬮潰鐨勮剼鏈潵鏇存柊cscope鍜宑tags鐨勭儲寮曟枃浠訛細<br> <br> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 50%; -moz-background-size: auto auto; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"> <div><img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" style="color: #0000ff;" alt="" align="top"><span style="color: #000000;"><span style="color: #008080;">#!/bin/sh</span><br> <img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top"><br> <img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top"><span style="color: #0000ff;">find</span> . -name "*.h" -o -name "*.c" -o -name "*.cc" > cscope.files<br> <img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top"><span style="color: #0000ff;">cscope</span> -bkq -i cscope.files<br style="color: #000000;"> <img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" style="color: #000000;" alt="" align="top"><span style="color: #000000;"><span style="color: #0000ff;">ctags</span> -R</span></span><br> </div> </div> <br> 榪欎釜鑴氭湰錛岄鍏堜嬌鐢╢ind鍛戒護錛屾煡鎵懼綋鍓嶇洰褰曞強瀛愮洰褰曚腑鎵鏈夊悗緙鍚嶄負".h", ".c"鍜?.cc"鐨勬枃浠訛紝騫舵妸鏌ユ壘緇撴灉閲嶅畾鍚戝埌鏂囦歡cscope.files涓?br> 鐒跺悗cscope鏍規嵁cscope.files涓殑鎵鏈夋枃浠訛紝鐢熸垚絎﹀彿绱㈠紩鏂囦歡銆?br> 鏈鍚庝竴鏉″懡浠や嬌鐢╟tags鍛戒護錛岀敓鎴愪竴涓猼ags鏂囦歡錛屽湪vim涓墽琛?:help tags"鍛戒護鏌ヨ瀹冪殑鐢ㄦ硶銆傚畠鍙互鍜宑scope涓璧蜂嬌鐢ㄣ?br> <br> 鐩墠鍙兘鍦╱nix緋誨垪鎿嶄綔緋葷粺涓嬩嬌鐢╟scope錛岃櫧鐒朵篃鏈墂indows鐗堟湰鐨刢scope錛屼笉榪囪繕鏈夊緢澶歜ug銆傚湪Linux鎶鏈腑鍧氱珯涓婄湅鍒版湁浣滆呭湪win2000涓婃垚鍔熻繍琛屼簡gvim + cscope錛岃鎯呭彲浠ュ弬闃咃細<br> <a style="color: #0000ff;" target="_blank"><u>http://www.chinalinuxpub.com/bbs/showthread.php?t=30185</u></a><br> <br> <br> <br> cscope鐨勪富欏靛湪錛?a style="color: #0000ff;" target="_blank"><u>http://cscope.sourceforge.net/</u></a><br> <br> 鍦╲im鐨勭綉绔欎笂錛屾湁寰堝鍜宑scope鐩稿叧鐨勬彃浠訛紝鍙互鍘繪壘涓涓嬩綘鏈夋病鏈夋墍鎰熷叴瓚g殑銆傛悳绱㈢粨鏋滃湪榪欓噷錛?br> <a style="color: #0000ff;" target="_blank"><u>鐐硅繖閲?/u></a><br> <br> <br> <pre>涓轟簡鏂逛究鍦頒嬌鐢╟scope錛屾垜浠繕闇瑕佷笅杞絚scope鐨勯敭鐩樻槧灝勮緗紝<br>榪欐牱灝卞彲浠ュ湪gvim涓畝鍗曞湴閫氳繃蹇嵎閿潵浣跨敤 cscope錛岃屼笉蹇呮暡澶嶆潅鐨勫懡浠や簡銆傞敭鐩樻槧灝勫彲浠ヤ粠<br>榪欓噷涓嬭澆錛?a >http://cscope.sourceforge.net/cscope_maps.vim</a></pre> <pre>灝嗕笅杞藉埌鐨?cscope_maps.vim <br></pre> <table style="border-collapse: collapse;" width="360" align="center" border="1" bordercolor="#dddddd" cellpadding="0" cellspacing="0"> <tbody> <tr height="60"> <td width="60" align="center"><img src="http://blog.chinaunix.net/fileicon/zip.gif" alt="" border="0"></td> <td> <table style="border-collapse: collapse;" width="100%" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr height="20"> <td width="40" align="center">鏂囦歡:</td> <td>cscope_maps.vim.tar.gz</td> </tr> <tr height="20"> <td width="40" align="center">澶у皬:</td> <td>2KB</td> </tr> <tr height="20"> <td width="40" align="center">涓嬭澆:</td> <td><a >涓嬭澆</a></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <pre><br>鏀懼湪gvim鐨勬彃浠剁洰褰曢噷錛屽 C:\Program Files\Vim\vimfiles\plugin 涓侺inux鐢ㄦ埛鍙互鏀懼湪 <br>$HOME/.vim/plugin 涓?/pre> <pre>↑<br>寤虹珛絎﹀彿鏁版嵁搴?†<br>鎴戜滑鍋囪鎴戜滑瑕侀槄璇葷殑浠g爜鏀懼湪 D:\src\myproject 涓嬨傜劧鍚庢墦寮鍛戒護琛岋紝榪涘叆婧愪唬鐮佹墍鍦ㄧ殑鐩綍錛?br>涓?cscope 寤虹珛鎼滅儲鏂囦歡鍒楄〃銆傚湪鍛戒護琛屼腑鎵ц浠ヤ笅鍛戒護錛?/pre> <pre>dir /s /b *.c *.h > cscope.files<br>濡傛灉浣犵殑婧愪唬鐮佹槸C++錛屽垯鍙互灝?cpp 絳夋墿灞曞悕涔熷姞鍏ュ埌涓婇潰鐨勫懡浠や腑銆?/pre> <pre>dir /s /b *.c *.h *cpp *.hpp > cscope.files<br>濡傛灉鏄疞inux鐢ㄦ埛錛屽垯鍙互浣跨敤 find 鍛戒護瀹炵幇鍚屾牱鐨勫姛鑳斤細</pre> <pre>find $(pwd) -name "*.[ch]"<br>鐒跺悗鎵ц浠ヤ笅鍛戒護錛?/pre> <pre>cscope -b<br>鎵ц緇撴潫鍚庝綘鍙互鍦ㄥ綋鍓嶇洰褰曚笅鍙戠幇 cscope.out 鏂囦歡錛岃繖灝辨槸 cscope 寤虹珛鐨勭鍙鋒暟鎹簱銆?/pre> <pre>涓婇潰榪欎釜鍛戒護涓紝-b鍙傛暟浣垮緱cscope涓嶅惎鍔ㄨ嚜甯︾殑鐢ㄦ埛鐣岄潰錛岃屼粎浠呭緩绔嬬鍙鋒暟鎹簱銆?/pre> <pre>↑<br>嫻忚婧愪唬鐮?†<br>浣跨敤 gvim 鎵撳紑浣犵殑婧愪唬鐮佺洰褰曚腑浠繪剰涓涓狢紼嬪簭鏂囦歡銆傜劧鍚庡湪gvim涓墽琛屽涓嬪懡浠わ細</pre> <pre>:cscope add D:\src\myproject\cscope.out<br>鐢變簬鍦?gvim 涓彲浠ヤ嬌鐢ㄥ懡浠ょ緝鍐欙紝鍥犳涓婇潰鐨勫懡浠ゅ彲浠ュ啓鎴愶細</pre> <pre>:cs a D:\src\myproject\cscope.out<br>榪欐牱灝辨墦寮浜嗗垰鍒氬緩绔嬬殑絎﹀彿鏁版嵁搴撱傞氳繃涓嬮潰鐨勫懡浠ゅ彲浠ユ鏌ユ暟鎹簱榪炴帴鐨勫瓨鍦ㄣ?/pre> <pre>:cscope show<br>璇ュ懡浠ゅ彲浠ョ緝鍐欎負</pre> <pre>:cs s<br>鐜板湪灝嗗厜鏍囩Щ鍔ㄥ埌婧愪唬鐮佷腑鐨勬煇涓嚱鏁板悕涓婏紝渚濇鎸変笅涓涓嬬粍鍚堥敭錛?/pre> <pre>s<br>紼嶇瓑鐗囧埢涔嬪悗浣犱細鍦ㄥ睆騫曚笅鏀劇湅鍒板涓嬬殑瀛楁牱*1錛?/pre> <pre>Cscope tag: display<br>   #   line filename / context / line<br>   1    342 D:\src\myproject\src\global.h <><br>             void display(void );<br>   2    616 D:\src\myproject\src\command.c <><br>             display();<br>   3    138 D:\src\myproject\src\display.c <><br>             display(void )<br>   4    385 D:\src\myproject\src\main.c <><br>             display();<br>   5    652 D:\src\myproject\src\main.c <><br>             display();<br>   6    663 D:\src\myproject\src\main.c <><br>             display();<br>Enter nr or choice ( to abort):<br>榪欓噷鏄劇ず鍑虹殑灝辨槸鏁翠釜宸ョ▼涓嬌鐢ㄥ埌浜?display 榪欎釜鏍囪瘑絎︾殑浣嶇疆銆傛鏃惰緭鍏?4錛屽洖杞︼紝<br>鍗沖彲璺寵漿鍒?main.c 鐨?385 琛岃皟鐢?display() 鍑芥暟鐨勫湴鏂硅繘琛屾祻瑙堛傛祻瑙堢粨鏉熷悗鎸?鎴栬?<br>鍙互鍥炲埌璺寵漿鍓嶇殑浣嶇疆銆?/pre> <pre>鐒跺悗灝嗗厜鏍囩Щ鍔ㄥ埌婧愪唬鐮佹煇涓嚱鏁板悕涓婏紝榪呴熷湴渚濇瀹変笅闈㈢殑緇勫悎閿細</pre> <pre>s<br>鍏朵腑 鎸?Ctrl-2 鍗沖彲杈撳叆銆傚悓鏍鳳紝灞忓箷涓婂嚭鐜頒簡涓鎺掔粨鏋滐紝閫夋嫨涔嬪悗浣犱細鍙戠幇錛?br>璺寵漿鍒扮殑鏂囦歡灝嗗湪姘村鉤鏂瑰悜鐨勬柊紿楀彛涓墦寮銆?/pre> <pre>鐒跺悗灝嗗厜鏍囩Щ鍔ㄥ埌婧愪唬鐮佹煇涓嚱鏁板悕涓婏紝榪呴熷湴渚濇瀹変笅闈㈢殑緇勫悎閿細</pre> <pre>s<br>閫夋嫨涔嬪悗浣犱細鍙戠幇錛岃煩杞埌鐨勬枃浠跺皢鍦ㄥ瀭鐩存柟鍚戠殑鏂扮獥鍙d腑鎵撳紑銆?/pre> <pre>浠ヤ笂鎴戜滑綆鍗曚粙緇嶄簡cscope鐨勪嬌鐢ㄦ柟娉曪紝鍏朵腑鎴戜滑鍙敤鍒頒簡涓涓?s 鍛戒護錛屽嵆璺熷湪 鍜?鍚庨潰鐨?s 閿?br>鍚屾牱錛屾垜浠彲浠ヤ嬌鐢ㄤ互涓嬬殑鍔熻兘閿疄鐜頒笉鍚岀殑璺寵漿鍔熻兘銆?/pre> <pre>c: 鏌ユ壘璇ュ嚱鏁拌璋冪敤鐨勪綅緗?<br>d: 鏌ユ壘璇ュ嚱鏁拌皟鐢ㄤ簡鍝簺鍑芥暟 <br>e: 鏌ユ壘鎸囧畾鐨勬瑙勮〃杈懼紡 <br>f: 鏌ユ壘鎸囧畾鐨勬枃浠?<br>g: 鏌ユ壘鎸囧畾鏍囪瘑絎︾殑瀹氫箟浣嶇疆 <br>i: 鏌ユ壘璇ユ枃浠跺湪鍝簺鍦版柟琚寘鍚?<br>s: 鏌ユ壘鎸囧畾鏍囪瘑絎︾殑浣跨敤浣嶇疆 <br>t: 鏌ユ壘鎸囧畾鐨勬枃鏈瓧絎︿覆<br>↑<br>鍛戒護琛屼嬌鐢ㄨ鏄?†<br>闄や簡涓婅堪閫氳繃蹇嵎閿槧灝勭殑鏂瑰紡浣跨敤cscope涔嬪錛屼篃鍙互鐩存帴鍦╣vim鍛戒護琛屼腑浣跨敤cscope銆傝繖鏍峰氨鍙互<br>闅忔剰瀹氫箟鏌ユ壘瀛楃涓詫紝鑰屼笉蹇呭眬闄愪簬婧愪唬鐮佷腑宸叉湁鐨勬爣璇嗙銆傚懡浠ゆ牸寮忓涓嬶細</pre> <pre>:cscope find <鍏抽敭瀛?gt;<br>璇ュ懡浠ゅ彲浠ョ緝鍐欎負</pre> <pre>:cs f <鍏抽敭瀛?gt;<br>涓涓瘮杈冨疄鐢ㄧ殑鎶宸ф槸浣跨敤cscope鎵撳紑鏂囦歡銆備嬌鐢ㄤ互涓嬪懡浠ゅ嵆鍙洿鎺ユ墦寮鍚嶄負display.c鐨勬枃浠訛紝<br>鑰屼笉蹇呭厛鍒囨崲鍒癲isplay.c鎵鍦ㄧ殑鐩綍銆?/pre> <pre>:cs f f display.c<br>cscope涔熸敮鎸佹瑙勮〃杈懼紡銆傚鏋滆涓嶆竻鏌愪釜鍑芥暟鐨勫悕縐幫紝鍙互鐢ㄤ笅闈㈢殑鏂瑰紡鏉ユ壘鍒拌鍑芥暟鐨勫畾涔変綅緗?/pre> <pre>:cs f g .*SetConfiguration.*<br>↑<br>鐗堟潈 †<br>Cscope铏界劧涓嶆槸GPL鐗堟潈錛屼絾鏄疌scope鏄紑鏀炬簮鐮佺殑鑷敱杞歡錛屼嬌鐢–scope鏃犻』鏀粯浠諱綍璐圭敤銆?/pre> <pre>↑<br>鍙傝?†<br>Cscope瀹樻柟涓婚〉, <a >http://cscope.sourceforge.net/</a> <br>The Vim/Cscope tutorial, <a >http://cscope.sourceforge.net/cscope_vim_tutorial.html</a> <br>Cscope on Win32, <a >http://iamphet.nm.ru/cscope/</a> <br>Vim涓叧浜?cscope 鐨勫府鍔╋紝浣跨敤 :help cscope 鍛戒護鏌ョ湅</pre><img src ="http://m.shnenglu.com/kenwell/aggbug/124226.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kenwell/" target="_blank">c++ 瀛︿範</a> 2010-08-21 22:28 <a href="http://m.shnenglu.com/kenwell/archive/2010/08/21/124226.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Windows Socket浜旂I/O妯″瀷鈥斺斾唬鐮佸叏鏀葷暐錛堜笅錛?/title><link>http://m.shnenglu.com/kenwell/archive/2010/08/03/122086.html</link><dc:creator>c++ 瀛︿範</dc:creator><author>c++ 瀛︿範</author><pubDate>Tue, 03 Aug 2010 09:27:00 GMT</pubDate><guid>http://m.shnenglu.com/kenwell/archive/2010/08/03/122086.html</guid><wfw:comment>http://m.shnenglu.com/kenwell/comments/122086.html</wfw:comment><comments>http://m.shnenglu.com/kenwell/archive/2010/08/03/122086.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/kenwell/comments/commentRss/122086.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kenwell/services/trackbacks/122086.html</trackback:ping><description><![CDATA[<p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">2.鐢ㄥ畬鎴愪緥紼嬫柟寮忓疄鐜扮殑閲嶅彔I/O妯″瀷<br style="line-height: normal; ">#include <WINSOCK2.H><br style="line-height: normal; ">#include <stdio.h></p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">#define PORT    5150<br style="line-height: normal; ">#define MSGSIZE 1024</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">#pragma comment(lib, "ws2_32.lib")</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">typedef struct<br style="line-height: normal; ">{<br style="line-height: normal; ">WSAOVERLAPPED overlap;<br style="line-height: normal; ">WSABUF        Buffer;<br style="line-height: normal; ">char          szMessage[MSGSIZE];<br style="line-height: normal; ">DWORD         NumberOfBytesRecvd;<br style="line-height: normal; ">DWORD         Flags; <br style="line-height: normal; ">SOCKET        sClient;<br style="line-height: normal; ">}PER_IO_OPERATION_DATA, *LPPER_IO_OPERATION_DATA;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">DWORD WINAPI WorkerThread(LPVOID);<br style="line-height: normal; ">void CALLBACK CompletionROUTINE(DWORD, DWORD, LPWSAOVERLAPPED, DWORD);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">SOCKET g_sNewClientConnection;<br style="line-height: normal; ">BOOL   g_bNewConnectionArrived = FALSE;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">int main()<br style="line-height: normal; ">{<br style="line-height: normal; ">WSADATA     wsaData;<br style="line-height: normal; ">SOCKET      sListen;<br style="line-height: normal; ">SOCKADDR_IN local, client;<br style="line-height: normal; ">DWORD       dwThreadId;<br style="line-height: normal; ">int         iaddrSize = sizeof(SOCKADDR_IN);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Initialize Windows Socket library<br style="line-height: normal; ">WSAStartup(0x0202, &wsaData);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Create listening socket<br style="line-height: normal; ">sListen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Bind<br style="line-height: normal; ">local.sin_addr.S_un.S_addr = htonl(INADDR_ANY);<br style="line-height: normal; ">local.sin_family = AF_INET;<br style="line-height: normal; ">local.sin_port = htons(PORT);<br style="line-height: normal; ">bind(sListen, (struct sockaddr *)&local, sizeof(SOCKADDR_IN));</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Listen<br style="line-height: normal; ">listen(sListen, 3);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Create worker thread<br style="line-height: normal; ">CreateThread(NULL, 0, WorkerThread, NULL, 0, &dwThreadId);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">while (TRUE)<br style="line-height: normal; ">{<br style="line-height: normal; ">    // Accept a connection<br style="line-height: normal; ">    g_sNewClientConnection = accept(sListen, (struct sockaddr *)&client, &iaddrSize);<br style="line-height: normal; ">    g_bNewConnectionArrived = TRUE;<br style="line-height: normal; ">    printf("Accepted client:%s:%d\n", inet_ntoa(client.sin_addr), ntohs(client.sin_port));<br style="line-height: normal; ">}<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">DWORD WINAPI WorkerThread(LPVOID lpParam)<br style="line-height: normal; ">{<br style="line-height: normal; ">LPPER_IO_OPERATION_DATA lpPerIOData = NULL;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">while (TRUE)<br style="line-height: normal; ">{<br style="line-height: normal; ">    if (g_bNewConnectionArrived)<br style="line-height: normal; ">    {<br style="line-height: normal; ">      // Launch an asynchronous operation for new arrived connection<br style="line-height: normal; ">      lpPerIOData = (LPPER_IO_OPERATION_DATA)HeapAlloc(<br style="line-height: normal; ">        GetProcessHeap(),<br style="line-height: normal; ">        HEAP_ZERO_MEMORY,<br style="line-height: normal; ">        sizeof(PER_IO_OPERATION_DATA));<br style="line-height: normal; ">      lpPerIOData->Buffer.len = MSGSIZE;<br style="line-height: normal; ">      lpPerIOData->Buffer.buf = lpPerIOData->szMessage;<br style="line-height: normal; ">      lpPerIOData->sClient = g_sNewClientConnection;<br style="line-height: normal; ">      <br style="line-height: normal; ">      WSARecv(lpPerIOData->sClient,<br style="line-height: normal; ">        &lpPerIOData->Buffer,<br style="line-height: normal; ">        1,<br style="line-height: normal; ">        &lpPerIOData->NumberOfBytesRecvd,<br style="line-height: normal; ">        &lpPerIOData->Flags,<br style="line-height: normal; ">        &lpPerIOData->overlap,<br style="line-height: normal; ">        CompletionROUTINE);      <br style="line-height: normal; ">      <br style="line-height: normal; ">      g_bNewConnectionArrived = FALSE;<br style="line-height: normal; ">    }</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">    SleepEx(1000, TRUE);<br style="line-height: normal; ">}<br style="line-height: normal; ">return 0;<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">void CALLBACK CompletionROUTINE(DWORD dwError,<br style="line-height: normal; ">                                DWORD cbTransferred,<br style="line-height: normal; ">                                LPWSAOVERLAPPED lpOverlapped,<br style="line-height: normal; ">                                DWORD dwFlags)<br style="line-height: normal; ">{<br style="line-height: normal; ">LPPER_IO_OPERATION_DATA lpPerIOData = (LPPER_IO_OPERATION_DATA)lpOverlapped;<br style="line-height: normal; "><br style="line-height: normal; ">if (dwError != 0 || cbTransferred == 0)<br style="line-height: normal; ">{<br style="line-height: normal; ">    // Connection was closed by client<br style="line-height: normal; ">closesocket(lpPerIOData->sClient);<br style="line-height: normal; ">HeapFree(GetProcessHeap(), 0, lpPerIOData);<br style="line-height: normal; ">}<br style="line-height: normal; ">else<br style="line-height: normal; ">{<br style="line-height: normal; ">    lpPerIOData->szMessage[cbTransferred] = '\0';<br style="line-height: normal; ">    send(lpPerIOData->sClient, lpPerIOData->szMessage, cbTransferred, 0);<br style="line-height: normal; ">    <br style="line-height: normal; ">    // Launch another asynchronous operation<br style="line-height: normal; ">    memset(&lpPerIOData->overlap, 0, sizeof(WSAOVERLAPPED));<br style="line-height: normal; ">    lpPerIOData->Buffer.len = MSGSIZE;<br style="line-height: normal; ">    lpPerIOData->Buffer.buf = lpPerIOData->szMessage;   </p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">    WSARecv(lpPerIOData->sClient,<br style="line-height: normal; ">      &lpPerIOData->Buffer,<br style="line-height: normal; ">      1,<br style="line-height: normal; ">      &lpPerIOData->NumberOfBytesRecvd,<br style="line-height: normal; ">      &lpPerIOData->Flags,<br style="line-height: normal; ">      &lpPerIOData->overlap,<br style="line-height: normal; ">      CompletionROUTINE);<br style="line-height: normal; ">}<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">鐢ㄥ畬鎴愪緥紼嬫潵瀹炵幇閲嶅彔I/O姣旂敤浜嬩歡閫氱煡綆鍗曞緱澶氥傚湪榪欎釜妯″瀷涓紝涓葷嚎紼嬪彧鐢ㄤ笉鍋滅殑鎺ュ彈榪炴帴鍗沖彲錛涜緟鍔╃嚎紼嬪垽鏂湁娌℃湁鏂扮殑瀹㈡埛绔繛鎺ヨ寤虹珛錛屽鏋滄湁錛屽氨涓洪偅涓鎴風濂楁帴瀛楁縺媧諱竴涓紓姝ョ殑WSARecv鎿嶄綔錛岀劧鍚庤皟鐢⊿leepEx浣跨嚎紼嬪浜庝竴縐嶅彲璀﹀憡鐨勭瓑寰呯姸鎬侊紝浠ヤ嬌寰桰/O瀹屾垚鍚嶤ompletionROUTINE鍙互琚唴鏍歌皟鐢ㄣ傚鏋滆緟鍔╃嚎紼嬩笉璋冪敤SleepEx錛屽垯鍐呮牳鍦ㄥ畬鎴愪竴嬈/O鎿嶄綔鍚庯紝鏃犳硶璋冪敤瀹屾垚渚嬬▼錛堝洜涓哄畬鎴愪緥紼嬬殑榪愯搴旇鍜屽綋鍒濇縺媧籛SARecv寮傛鎿嶄綔鐨勪唬鐮佸湪鍚屼竴涓嚎紼嬩箣鍐咃級銆?br style="line-height: normal; ">瀹屾垚渚嬬▼鍐呯殑瀹炵幇浠g爜姣旇緝綆鍗曪紝瀹冨彇鍑烘帴鏀跺埌鐨勬暟鎹紝鐒跺悗灝嗘暟鎹師灝佷笉鍔ㄧ殑鍙戦佺粰瀹㈡埛绔紝鏈鍚庨噸鏂版縺媧誨彟涓涓猈SARecv寮傛鎿嶄綔銆傛敞鎰忥紝鍦ㄨ繖閲岀敤鍒頒簡“灝鵑殢鏁版嵁”銆傛垜浠湪璋冪敤WSARecv鐨勬椂鍊欙紝鍙傛暟lpOverlapped瀹為檯涓婃寚鍚戜竴涓瘮瀹冨ぇ寰楀鐨勭粨鏋凱ER_IO_OPERATION_DATA錛岃繖涓粨鏋勯櫎浜哤SAOVERLAPPED浠ュ錛岃繕琚垜浠檮鍔犱簡緙撳啿鍖虹殑緇撴瀯淇℃伅錛屽彟澶栬繕鍖呮嫭瀹㈡埛绔鎺ュ瓧絳夐噸瑕佺殑淇℃伅銆傝繖鏍鳳紝鍦ㄥ畬鎴愪緥紼嬩腑閫氳繃鍙傛暟lpOverlapped鎷垮埌鐨勪笉浠呬粎鏄疻SAOVERLAPPED緇撴瀯錛岃繕鏈夊悗杈瑰熬闅忕殑鍖呭惈瀹㈡埛绔鎺ュ瓧鍜屾帴鏀舵暟鎹紦鍐插尯絳夐噸瑕佷俊鎭傝繖鏍風殑C璇█鎶宸у湪鎴戝悗闈粙緇嶅畬鎴愮鍙g殑鏃跺欒繕浼氫嬌鐢ㄥ埌銆?/p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">浜?瀹屾垚绔彛妯″瀷<br style="line-height: normal; ">“瀹屾垚绔彛”妯″瀷鏄縿浠婁負姝㈡渶涓哄鏉傜殑涓縐岻/O妯″瀷銆傜劧鑰岋紝鍋囪嫢涓涓簲鐢ㄧ▼搴忓悓鏃墮渶瑕佺鐞嗕負鏁頒紬澶氱殑濂楁帴瀛楋紝閭d箞閲囩敤榪欑妯″瀷錛屽線寰鍙互杈懼埌鏈浣崇殑緋葷粺鎬ц兘錛佷絾涓嶅垢鐨勬槸錛岃妯″瀷鍙傜敤浜嶹indows NT鍜學indows 2000鎿嶄綔緋葷粺銆傚洜鍏惰璁$殑澶嶆潅鎬э紝鍙湁鍦ㄤ綘鐨勫簲鐢ㄧ▼搴忛渶瑕佸悓鏃剁鐞嗘暟鐧句箖鑷充笂鍗冧釜濂楁帴瀛楃殑鏃跺欙紝鑰屼笖甯屾湜闅忕潃緋葷粺鍐呭畨瑁呯殑CPU鏁伴噺鐨勫澶氾紝搴旂敤紼嬪簭鐨勬ц兘涔熷彲浠ョ嚎鎬ф彁鍗囷紝鎵嶅簲鑰冭檻閲囩敤“瀹屾垚绔彛”妯″瀷銆傝璁頒綇鐨勪竴涓熀鏈噯鍒欐槸錛屽亣濡傝涓篧indows NT鎴朩indows 2000寮鍙戦珮鎬ц兘鐨勬湇鍔″櫒搴旂敤錛屽悓鏃跺笇鏈涗負澶ч噺濂楁帴瀛桰/O璇鋒眰鎻愪緵鏈嶅姟錛圵eb鏈嶅姟鍣ㄤ究鏄繖鏂歸潰鐨勫吀鍨嬩緥瀛愶級錛岄偅涔圛/O瀹屾垚绔彛妯″瀷渚挎槸鏈浣抽夋嫨錛侊紙鑺傞夎嚜銆奧indows緗戠粶緙栫▼銆嬬鍏珷錛?br style="line-height: normal; ">瀹屾垚绔彛妯″瀷鏄垜鏈鍠滅埍鐨勪竴縐嶆ā鍨嬨傝櫧鐒跺叾瀹炵幇姣旇緝澶嶆潅錛堝叾瀹炴垜瑙夊緱瀹冪殑瀹炵幇姣旂敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營/O綆鍗曞浜嗭級錛屼絾鍏舵晥鐜囨槸鎯婁漢鐨勩傛垜鍦═鍏徃鐨勬椂鍊欐浘緇忓府鍚屼簨鍐欒繃涓涓偖浠舵湇鍔″櫒鐨勬ц兘嫻嬭瘯紼嬪簭錛岀敤鐨勫氨鏄畬鎴愮鍙fā鍨嬨傜粨鏋滆〃鏄庯紝瀹屾垚绔彛妯″瀷鍦ㄥ榪炴帴錛堟垚鍗冧笂涓囷級鐨勬儏鍐典笅錛屼粎浠呬緷闈犱竴涓や釜杈呭姪綰跨▼錛屽氨鍙互杈懼埌闈炲父楂樼殑鍚炲悙閲忋備笅闈㈡垜榪樻槸浠庝唬鐮佽璧鳳細<br style="line-height: normal; ">#include <WINSOCK2.H><br style="line-height: normal; ">#include <stdio.h></p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">#define PORT    5150<br style="line-height: normal; ">#define MSGSIZE 1024</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">#pragma comment(lib, "ws2_32.lib")</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">typedef enum<br style="line-height: normal; ">{<br style="line-height: normal; ">RECV_POSTED<br style="line-height: normal; ">}OPERATION_TYPE;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">typedef struct<br style="line-height: normal; ">{<br style="line-height: normal; ">WSAOVERLAPPED overlap;<br style="line-height: normal; ">WSABUF         Buffer;<br style="line-height: normal; ">char           szMessage[MSGSIZE];<br style="line-height: normal; ">DWORD          NumberOfBytesRecvd;<br style="line-height: normal; ">DWORD          Flags;<br style="line-height: normal; ">OPERATION_TYPE OperationType;<br style="line-height: normal; ">}PER_IO_OPERATION_DATA, *LPPER_IO_OPERATION_DATA;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">DWORD WINAPI WorkerThread(LPVOID);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">int main()<br style="line-height: normal; ">{<br style="line-height: normal; ">WSADATA                 wsaData;<br style="line-height: normal; ">SOCKET                  sListen, sClient;<br style="line-height: normal; ">SOCKADDR_IN             local, client;<br style="line-height: normal; ">DWORD                   i, dwThreadId;<br style="line-height: normal; ">int                     iaddrSize = sizeof(SOCKADDR_IN);<br style="line-height: normal; ">HANDLE                  CompletionPort = INVALID_HANDLE_VALUE;<br style="line-height: normal; ">SYSTEM_INFO             systeminfo;<br style="line-height: normal; ">LPPER_IO_OPERATION_DATA lpPerIOData = NULL;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Initialize Windows Socket library<br style="line-height: normal; ">WSAStartup(0x0202, &wsaData);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Create completion port<br style="line-height: normal; ">CompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Create worker thread<br style="line-height: normal; ">GetSystemInfo(&systeminfo);<br style="line-height: normal; ">for (i = 0; i < systeminfo.dwNumberOfProcessors; i++)<br style="line-height: normal; ">{<br style="line-height: normal; ">    CreateThread(NULL, 0, WorkerThread, CompletionPort, 0, &dwThreadId);<br style="line-height: normal; ">}<br style="line-height: normal; "><br style="line-height: normal; ">// Create listening socket<br style="line-height: normal; ">sListen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Bind<br style="line-height: normal; ">local.sin_addr.S_un.S_addr = htonl(INADDR_ANY);<br style="line-height: normal; ">local.sin_family = AF_INET;<br style="line-height: normal; ">local.sin_port = htons(PORT);<br style="line-height: normal; ">bind(sListen, (struct sockaddr *)&local, sizeof(SOCKADDR_IN));</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">// Listen<br style="line-height: normal; ">listen(sListen, 3);</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">while (TRUE)<br style="line-height: normal; ">{<br style="line-height: normal; ">    // Accept a connection<br style="line-height: normal; ">    sClient = accept(sListen, (struct sockaddr *)&client, &iaddrSize);<br style="line-height: normal; ">    printf("Accepted client:%s:%d\n", inet_ntoa(client.sin_addr), ntohs(client.sin_port));</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">    // Associate the newly arrived client socket with completion port<br style="line-height: normal; ">    CreateIoCompletionPort((HANDLE)sClient, CompletionPort, (DWORD)sClient, 0);<br style="line-height: normal; ">    <br style="line-height: normal; ">    // Launch an asynchronous operation for new arrived connection<br style="line-height: normal; ">    lpPerIOData = (LPPER_IO_OPERATION_DATA)HeapAlloc(<br style="line-height: normal; ">      GetProcessHeap(),<br style="line-height: normal; ">      HEAP_ZERO_MEMORY,<br style="line-height: normal; ">      sizeof(PER_IO_OPERATION_DATA));<br style="line-height: normal; ">    lpPerIOData->Buffer.len = MSGSIZE;<br style="line-height: normal; ">    lpPerIOData->Buffer.buf = lpPerIOData->szMessage;<br style="line-height: normal; ">    lpPerIOData->OperationType = RECV_POSTED;<br style="line-height: normal; ">    WSARecv(sClient,<br style="line-height: normal; ">      &lpPerIOData->Buffer,<br style="line-height: normal; ">      1,<br style="line-height: normal; ">      &lpPerIOData->NumberOfBytesRecvd,<br style="line-height: normal; ">      &lpPerIOData->Flags,<br style="line-height: normal; ">      &lpPerIOData->overlap,<br style="line-height: normal; ">      NULL);<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">PostQueuedCompletionStatus(CompletionPort, 0xFFFFFFFF, 0, NULL);<br style="line-height: normal; ">CloseHandle(CompletionPort);<br style="line-height: normal; ">closesocket(sListen);<br style="line-height: normal; ">WSACleanup();<br style="line-height: normal; ">return 0;<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">DWORD WINAPI WorkerThread(LPVOID CompletionPortID)<br style="line-height: normal; ">{<br style="line-height: normal; ">HANDLE                  CompletionPort=(HANDLE)CompletionPortID;<br style="line-height: normal; ">DWORD                   dwBytesTransferred;<br style="line-height: normal; ">SOCKET                  sClient;<br style="line-height: normal; ">LPPER_IO_OPERATION_DATA lpPerIOData = NULL;</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">while (TRUE)<br style="line-height: normal; ">{<br style="line-height: normal; ">    GetQueuedCompletionStatus(<br style="line-height: normal; ">      CompletionPort,<br style="line-height: normal; ">      &dwBytesTransferred,<br style="line-height: normal; ">      &sClient,<br style="line-height: normal; ">      (LPOVERLAPPED *)&lpPerIOData,<br style="line-height: normal; ">      INFINITE);<br style="line-height: normal; ">    if (dwBytesTransferred == 0xFFFFFFFF)<br style="line-height: normal; ">    {<br style="line-height: normal; ">      return 0;<br style="line-height: normal; ">    }<br style="line-height: normal; ">    <br style="line-height: normal; ">    if (lpPerIOData->OperationType == RECV_POSTED)<br style="line-height: normal; ">    {<br style="line-height: normal; ">      if (dwBytesTransferred == 0)<br style="line-height: normal; ">      {<br style="line-height: normal; ">        // Connection was closed by client<br style="line-height: normal; ">        closesocket(sClient);<br style="line-height: normal; ">        HeapFree(GetProcessHeap(), 0, lpPerIOData);        <br style="line-height: normal; ">      }<br style="line-height: normal; ">      else<br style="line-height: normal; ">      {<br style="line-height: normal; ">        lpPerIOData->szMessage[dwBytesTransferred] = '\0';<br style="line-height: normal; ">        send(sClient, lpPerIOData->szMessage, dwBytesTransferred, 0);<br style="line-height: normal; ">        <br style="line-height: normal; ">        // Launch another asynchronous operation for sClient<br style="line-height: normal; ">        memset(lpPerIOData, 0, sizeof(PER_IO_OPERATION_DATA));<br style="line-height: normal; ">        lpPerIOData->Buffer.len = MSGSIZE;<br style="line-height: normal; ">        lpPerIOData->Buffer.buf = lpPerIOData->szMessage;<br style="line-height: normal; ">        lpPerIOData->OperationType = RECV_POSTED;<br style="line-height: normal; ">        WSARecv(sClient,<br style="line-height: normal; ">          &lpPerIOData->Buffer,<br style="line-height: normal; ">          1,<br style="line-height: normal; ">          &lpPerIOData->NumberOfBytesRecvd,<br style="line-height: normal; ">          &lpPerIOData->Flags,<br style="line-height: normal; ">          &lpPerIOData->overlap,<br style="line-height: normal; ">          NULL);<br style="line-height: normal; ">      }<br style="line-height: normal; ">    }<br style="line-height: normal; ">}<br style="line-height: normal; ">return 0;<br style="line-height: normal; ">}</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br style="line-height: normal; ">棣栧厛錛岃璇翠富綰跨▼錛?br style="line-height: normal; ">1.鍒涘緩瀹屾垚绔彛瀵硅薄<br style="line-height: normal; ">2.鍒涘緩宸ヤ綔鑰呯嚎紼嬶紙榪欓噷宸ヤ綔鑰呯嚎紼嬬殑鏁伴噺鏄寜鐓PU鐨勪釜鏁版潵鍐沖畾鐨勶紝榪欐牱鍙互杈懼埌鏈浣蟲ц兘錛?br style="line-height: normal; ">3.鍒涘緩鐩戝惉濂楁帴瀛楋紝緇戝畾錛岀洃鍚紝鐒跺悗紼嬪簭榪涘叆寰幆<br style="line-height: normal; ">4.鍦ㄥ驚鐜腑錛屾垜鍋氫簡浠ヤ笅鍑犱歡浜嬫儏錛?br style="line-height: normal; ">(1).鎺ュ彈涓涓鎴風榪炴帴<br style="line-height: normal; ">(2).灝嗚瀹㈡埛绔鎺ュ瓧涓庡畬鎴愮鍙g粦瀹氬埌涓璧?榪樻槸璋冪敤CreateIoCompletionPort錛屼絾榪欐鐨勪綔鐢ㄤ笉鍚?錛屾敞鎰忥紝鎸夐亾鐞嗘潵璁詫紝姝ゆ椂浼犻掔粰CreateIoCompletionPort鐨勭涓変釜鍙傛暟搴旇鏄竴涓畬鎴愰敭錛屼竴鑸潵璁詫紝紼嬪簭閮芥槸浼犻掍竴涓崟鍙ユ焺鏁版嵁緇撴瀯鐨勫湴鍧錛岃鍗曞彞鏌勬暟鎹寘鍚簡鍜岃瀹㈡埛绔繛鎺ユ湁鍏崇殑淇℃伅錛岀敱浜庢垜浠彧鍏沖績濂楁帴瀛楀彞鏌勶紝鎵浠ョ洿鎺ュ皢濂楁帴瀛楀彞鏌勪綔涓哄畬鎴愰敭浼犻掞紱<br style="line-height: normal; ">(3).瑙﹀彂涓涓猈SARecv寮傛璋冪敤錛岃繖嬈″張鐢ㄥ埌浜?#8220;灝鵑殢鏁版嵁”錛屼嬌鎺ユ敹鏁版嵁鎵鐢ㄧ殑緙撳啿鍖虹揣璺熷湪WSAOVERLAPPED瀵硅薄涔嬪悗錛屾澶栵紝榪樻湁鎿嶄綔綾誨瀷絳夐噸瑕佷俊鎭?br style="line-height: normal; "><br style="line-height: normal; ">鍦ㄥ伐浣滆呯嚎紼嬬殑寰幆涓紝鎴戜滑<br style="line-height: normal; ">1.璋冪敤GetQueuedCompletionStatus鍙栧緱鏈I/O鐨勭浉鍏充俊鎭紙渚嬪濂楁帴瀛楀彞鏌勩佷紶閫佺殑瀛楄妭鏁般佸崟I/O鏁版嵁緇撴瀯鐨勫湴鍧絳夌瓑錛?br style="line-height: normal; ">2.閫氳繃鍗旾/O鏁版嵁緇撴瀯鎵懼埌鎺ユ敹鏁版嵁緙撳啿鍖猴紝鐒跺悗灝嗘暟鎹師灝佷笉鍔ㄧ殑鍙戦佸埌瀹㈡埛绔?br style="line-height: normal; ">3.鍐嶆瑙﹀彂涓涓猈SARecv寮傛鎿嶄綔</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">鍏?浜旂I/O妯″瀷鐨勬瘮杈?br style="line-height: normal; ">鎴戜細浠庝互涓嬪嚑涓柟闈㈡潵榪涜姣旇緝<br style="line-height: normal; ">*鏈夋棤姣忕嚎紼?4榪炴帴鏁伴檺鍒?br style="line-height: normal; ">濡傛灉鍦ㄩ夋嫨妯″瀷涓病鏈夐噸鏂板畾涔塅D_SETSIZE瀹忥紝鍒欐瘡涓猣d_set榛樿鍙互瑁呬笅64涓猄OCKET銆傚悓鏍風殑錛屽彈MAXIMUM_WAIT_OBJECTS瀹忕殑褰卞搷錛屼簨浠墮夋嫨銆佺敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營/O閮芥湁姣忕嚎紼嬫渶澶?4榪炴帴鏁伴檺鍒躲傚鏋滆繛鎺ユ暟鎴愬崈涓婁竾錛屽垯蹇呴』瀵瑰鎴風濂楁帴瀛楄繘琛屽垎緇勶紝榪欐牱錛屽娍蹇呭鍔犵▼搴忕殑澶嶆潅搴︺?br style="line-height: normal; ">鐩稿弽錛屽紓姝ラ夋嫨銆佺敤瀹屾垚渚嬬▼瀹炵幇鐨勯噸鍙營/O鍜屽畬鎴愮鍙d笉鍙楁闄愬埗銆?/p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">*綰跨▼鏁?br style="line-height: normal; ">闄や簡寮傛閫夋嫨浠ュ錛屽叾浠栨ā鍨嬭嚦灝戦渶瑕?涓嚎紼嬨備竴涓富綰跨▼鍜屼竴涓緟鍔╃嚎紼嬨傚悓鏍風殑錛屽鏋滆繛鎺ユ暟澶т簬64錛屽垯閫夋嫨妯″瀷銆佷簨浠墮夋嫨鍜岀敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營/O鐨勭嚎紼嬫暟榪樿澧炲姞銆?/p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">*瀹炵幇鐨勫鏉傚害<br style="line-height: normal; ">鎴戠殑涓漢鐪嬫硶鏄紝鍦ㄥ疄鐜伴毦搴︿笂錛屽紓姝ラ夋嫨<閫夋嫨<鐢ㄥ畬鎴愪緥紼嬪疄鐜扮殑閲嶅彔I/O<浜嬩歡閫夋嫨<瀹屾垚绔彛<鐢ㄤ簨浠墮氱煡瀹炵幇鐨勯噸鍙營/O</p><p style="line-height: normal; color: rgb(59, 64, 67); font-family: Georgia; font-size: 12px; letter-spacing: 2px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">*鎬ц兘<br style="line-height: normal; ">鐢變簬閫夋嫨妯″瀷涓瘡嬈¢兘瑕侀噸璁捐闆嗭紝鍦╯elect鍑芥暟榪斿洖鍚庤繕瑕侀拡瀵規墍鏈夊鎺ュ瓧榪涜閫愪竴嫻嬭瘯錛屾垜鐨勬劅瑙夋槸鏁堢巼姣旇緝宸紱瀹屾垚绔彛鍜岀敤瀹屾垚渚嬬▼瀹炵幇鐨勯噸鍙營/O鍩烘湰涓婁笉娑夊強鍏ㄥ眬鏁版嵁錛屾晥鐜囧簲璇ユ槸鏈楂樼殑錛岃屼笖鍦ㄥ澶勭悊鍣ㄦ儏褰笅瀹屾垚绔彛榪樿楂樹竴浜涳紱浜嬩歡閫夋嫨鍜岀敤浜嬩歡閫氱煡瀹炵幇鐨勯噸鍙營/O鍦ㄥ疄鐜版満鍒朵笂閮芥槸閲囩敤WSAWaitForMultipleEvents錛屾劅瑙夋晥鐜囧樊涓嶅錛涜嚦浜庡紓姝ラ夋嫨錛屼笉濂芥瘮杈冦傛墍浠ユ垜鐨勭粨璁烘槸:閫夋嫨<鐢ㄤ簨浠墮氱煡瀹炵幇鐨勯噸鍙營/O<浜嬩歡閫夋嫨<鐢ㄥ畬鎴愪緥紼嬪疄鐜扮殑閲嶅彔I/O<瀹屾垚绔彛</p> <img src ="http://m.shnenglu.com/kenwell/aggbug/122086.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kenwell/" target="_blank">c++ 瀛︿範</a> 2010-08-03 17:27 <a href="http://m.shnenglu.com/kenwell/archive/2010/08/03/122086.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Windows Socket浜旂I/O妯″瀷鈥斺斾唬鐮佸叏鏀葷暐錛堜笂錛?/title><link>http://m.shnenglu.com/kenwell/archive/2010/08/03/122085.html</link><dc:creator>c++ 瀛︿範</dc:creator><author>c++ 瀛︿範</author><pubDate>Tue, 03 Aug 2010 09:26:00 GMT</pubDate><guid>http://m.shnenglu.com/kenwell/archive/2010/08/03/122085.html</guid><wfw:comment>http://m.shnenglu.com/kenwell/comments/122085.html</wfw:comment><comments>http://m.shnenglu.com/kenwell/archive/2010/08/03/122085.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/kenwell/comments/commentRss/122085.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kenwell/services/trackbacks/122085.html</trackback:ping><description><![CDATA[     鎽樿: 濡傛灉浣犳兂鍦╓indows騫沖彴涓婃瀯寤烘湇鍔″櫒搴旂敤錛岄偅涔圛/O妯″瀷鏄綘蹇呴』鑰冭檻鐨勩俉indows鎿嶄綔緋葷粺鎻愪緵浜嗛夋嫨錛圫elect錛夈佸紓姝ラ夋嫨錛圵SAAsyncSelect錛夈佷簨浠墮夋嫨錛圵SAEventSelect錛夈侀噸鍙營/O錛圤verlapped I/O錛夊拰瀹屾垚绔彛錛圕ompletion Port)鍏變簲縐岻/O妯″瀷銆傛瘡涓縐嶆ā鍨嬪潎閫傜敤浜庝竴縐嶇壒瀹氱殑搴旂敤鍦烘櫙銆傜▼搴忓憳搴旇瀵硅嚜宸辯殑搴旂敤闇姹傞潪甯告槑紜紝鑰屼笖緇煎悎鑰冭檻...  <a href='http://m.shnenglu.com/kenwell/archive/2010/08/03/122085.html'>闃呰鍏ㄦ枃</a><img src ="http://m.shnenglu.com/kenwell/aggbug/122085.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kenwell/" target="_blank">c++ 瀛︿範</a> 2010-08-03 17:26 <a href="http://m.shnenglu.com/kenwell/archive/2010/08/03/122085.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title> 寰堝菇榛樼殑璁茶В鍏Socket I/O妯″瀷(杞澆錛?/title><link>http://m.shnenglu.com/kenwell/archive/2010/08/03/122069.html</link><dc:creator>c++ 瀛︿範</dc:creator><author>c++ 瀛︿範</author><pubDate>Tue, 03 Aug 2010 07:50:00 GMT</pubDate><guid>http://m.shnenglu.com/kenwell/archive/2010/08/03/122069.html</guid><wfw:comment>http://m.shnenglu.com/kenwell/comments/122069.html</wfw:comment><comments>http://m.shnenglu.com/kenwell/archive/2010/08/03/122069.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/kenwell/comments/commentRss/122069.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/kenwell/services/trackbacks/122069.html</trackback:ping><description><![CDATA[     鎽樿: 鏈枃綆鍗曚粙緇嶄簡褰撳墠Windows鏀寔鐨勫悇縐峉ocket I/O妯″瀷錛屽鏋滀綘鍙戠幇鍏朵腑瀛樺湪浠涔堥敊璇鍔″繀璧愭暀銆備竴錛歴elect妯″瀷浜岋細WSAAsyncSelect妯″瀷涓夛細WSAEventSelect妯″瀷鍥涳細Overlapped I/O 浜嬩歡閫氱煡妯″瀷浜旓細Overlapped I/O 瀹屾垚渚嬬▼妯″瀷鍏細IOCP妯″瀷鑰侀檲鏈変竴涓湪澶栧湴宸ヤ綔鐨勫コ鍎匡紝涓嶈兘緇忓父鍥炴潵錛岃侀檲鍜屽ス閫氳繃淇′歡鑱旂郴銆備粬浠殑淇′細琚偖閫掑憳鎶曢掑埌浠栦滑鐨?..  <a href='http://m.shnenglu.com/kenwell/archive/2010/08/03/122069.html'>闃呰鍏ㄦ枃</a><img src ="http://m.shnenglu.com/kenwell/aggbug/122069.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/kenwell/" target="_blank">c++ 瀛︿範</a> 2010-08-03 15:50 <a href="http://m.shnenglu.com/kenwell/archive/2010/08/03/122069.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>shell 鍙橀噺闂存帴寮曠敤http://m.shnenglu.com/kenwell/archive/2010/08/02/121977.htmlc++ 瀛︿範c++ 瀛︿範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.html榪欑浣跨敤闂存帴寮曠敤鐨勬柟娉曟槸涓涓皬鎶宸? 濡傛灉絎簩涓彉閲忔洿鏀逛簡瀹冪殑鍊? 閭d箞絎竴涓彉閲?/div>
蹇呴』琚傚綋鐨勮В闄ゅ紩鐢?灝卞儚涓婅竟鐨勪緥瀛愪竴鏍?. 騫歌繍鐨勬槸, 鍦˙ash鐗堟湰2涓紩鍏?/div>
鐨?{!variable}褰㈠紡浣垮緱浣跨敤闂存帴寮曠敤鏇村姞鐩磋浜?
鍋囪涓涓彉閲忕殑鍊兼槸絎簩涓彉閲忕殑鍚嶅瓧. 閭d箞鎴戜滑濡備綍浠庣涓涓彉閲忎腑鍙栧緱絎簩涓彉閲忕殑鍊煎憿? 姣斿,
濡傛灉a=letter_of_alphabet騫朵笖letter_of_alphabet=z, 閭d箞鎴戜滑鑳藉閫氳繃寮曠敤鍙橀噺a鏉ヨ幏寰梲涔? 榪欑‘
瀹炴槸鍙互鍋氬埌鐨? 瀹冭縐頒負闂存帴寮曠敤. 瀹冧嬌鐢╡val var1=\$$var2榪欑涓嶅鉤甯哥殑褰㈠紡.


]]>Linux Shell Bash 姝e垯琛ㄨ揪寮忎粙緇?/title><link>http://m.shnenglu.com/kenwell/archive/2010/06/30/119014.html</link><dc:creator>c++ 瀛︿範</dc:creator><author>c++ 瀛︿範</author><pubDate>Wed, 30 Jun 2010 14:15:00 GMT</pubDate><guid>http://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>1</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>姝e垯琛ㄨ揪寮忓氨鏄敱涓緋誨垪鐗規畩瀛楃緇勬垚鐨勫瓧絎︿覆, 鍏朵腑姣忎釜鐗規畩瀛楃閮借縐頒負<em>鍏冨瓧絎?/em>, 榪欎簺<em>鍏冨瓧絎?/em>騫朵笉琛ㄧず涓哄畠浠瓧闈笂鐨勫惈涔? 鑰屼細琚В閲婁負涓浜涚壒瀹氱殑鍚箟. 鍏蜂釜渚嬪瓙, 姣斿寮曠敤絎﹀彿, 鍙兘灝辨槸琛ㄧず鏌愪漢鐨勬紨璁插唴瀹? <em>鍚屼笂</em>, 涔熷彲鑳借〃紺轟負鎴戜滑涓嬮潰灝嗚璁插埌鐨勭鍙風殑鍏?鍚箟. 姝e垯琛ㄨ揪寮忓叾瀹炴槸鐢辨櫘閫氬瓧絎﹀拰鍏冨瓧絎﹀叡鍚岀粍鎴愮殑闆嗗悎, 榪欎釜闆嗗悎鐢ㄦ潵鍖歸厤(鎴栨寚瀹?妯″紡. </p> <p>涓涓鍒欒〃杈懼紡浼氬寘鍚笅鍒椾竴欏規垨澶氶」:</p><ul> <li> <p><em class="FIRSTTERM">涓涓瓧絎﹂泦</em>. 榪欓噷鎵鎸囩殑瀛楃闆嗗彧鍖呭惈鏅氬瓧絎? 榪欎簺瀛楃鍙〃紺哄畠浠殑瀛楅潰鍚箟. 姝e垯琛ㄨ揪寮忕殑鏈綆鍗曞艦寮忓氨鏄?em>鍙?/em>鍖呭惈瀛楃闆? 鑰屼笉鍖呭惈鍏冨瓧絎? </p></li> <li> <p><em class="FIRSTTERM">閿?/em>. <em>閿?/em>鎸囧畾浜嗘鍒欒〃杈懼紡鎵瑕佸尮閰嶇殑鏂囨湰鍦ㄦ枃鏈涓墍澶勭殑浣嶇疆. 姣斿, <span id="hvzpftn" class="TOKEN">^</span>, 鍜?span class="TOKEN">$</span>灝辨槸閿? </p></li> <li> <p><em class="FIRSTTERM">淇グ絎?/em>. 瀹冧滑鎵╁ぇ鎴栫緝灝?<em>淇敼</em>)浜嗘鍒欒〃杈懼紡鍖歸厤鏂囨湰鐨勮寖鍥? 淇グ絎﹀寘鍚槦鍙? 鎷彿, 鍜屽弽鏂滄潬. </p></li></ul> <p>姝e垯琛ㄨ揪寮忔渶涓昏鐨勭洰鐨勫氨鏄敤浜?<em class="FIRSTTERM">RE</em>)鏂囨湰鎼滅儲涓庡瓧絎︿覆鎿嶄綔. (璇戣呮敞: 浠ヤ笅姝e垯琛ㄨ揪寮忎篃浼氳綆縐頒負<em>RE</em>.) RE鑳藉<em class="FIRSTTERM">鍖歸厤</em>鍗曚釜瀛楃鎴栬呬竴涓瓧絎﹂泦 -- 鍗? 涓涓瓧絎︿覆, 鎴栬呬竴涓瓧絎︿覆鐨勪竴閮ㄥ垎. </p> <ul> <li> <p>鏄熷彿 -- <span id="hvzpftn" class="TOKEN">*</span> -- 鐢ㄦ潵鍖歸厤瀹冨墠闈㈠瓧絎︾殑浠繪剰澶氭, <em>鍖呮嫭0嬈?/em>. </p> <p><span id="hvzpftn" class="QUOTE">"1133*"</span>鍖歸厤<tt class="REPLACEABLE"><em>11 + 涓涓垨澶氫釜3 + 涔熷厑璁稿悗杈硅繕鏈夊叾浠栧瓧絎?/em></tt>: <tt class="REPLACEABLE"><em>113</em></tt>, <tt class="REPLACEABLE"><em>1133</em></tt>, <tt class="REPLACEABLE"><em>111312</em></tt>, 絳夌瓑.</p></li> <li> <p><a name="REGEXDOT"></a>鐐?-- <span id="hvzpftn" class="TOKEN">.</span> -- 鐢ㄤ簬鍖歸厤浠繪剰涓涓瓧絎? 闄や簡鎹㈣絎? <a name="AEN13724"><span id="hvzpftn" class="footnote">[1]</span></a> </p> <p><span id="hvzpftn" class="QUOTE">"13."</span> 鍖歸厤<tt class="REPLACEABLE"><em>13 + 鑷沖皯涓涓換鎰忓瓧絎?鍖呮嫭絀烘牸)</em></tt>: <tt class="REPLACEABLE"><em>1133</em></tt>, <tt class="REPLACEABLE"><em>11333</em></tt>, 浣嗕笉鑳藉尮閰?tt class="REPLACEABLE"><em>13</em></tt> (鍥犱負緙哄皯"."鎵鑳藉尮閰嶇殑鑷沖皯涓涓換鎰忓瓧絎?. </p></li> <li> <p>鑴卞瓧絎﹀彿 -- <span id="hvzpftn" class="TOKEN">^</span> -- 鍖歸厤琛岄, 浣嗘槸鏌愪簺鏃跺欓渶瑕佷緷璧栦笂涓嬫枃鐜, 鍦≧E涓? 鏈夋椂鍊欎篃琛ㄧず瀵逛竴涓瓧絎﹂泦鍙栧弽. </p></li> <li> <p><a name="DOLLARSIGNREF"></a></p> <p>緹庡厓絎?-- <span id="hvzpftn" class="TOKEN">$</span> -- 鍦≧E涓敤鏉ュ尮閰嶈灝? </p> <p><span id="hvzpftn" class="QUOTE">"XXX$"</span> 鍖歸厤琛屽熬鐨?em>XXX</em>. </p> <p><span id="hvzpftn" class="QUOTE">"^$"</span> 鍖歸厤絀鴻. </p></li> <li> <p><a name="BRACKETSREF"></a></p> <p>涓嫭鍙?-- <span id="hvzpftn" class="TOKEN">[...]</span> -- 鍦≧E涓? 灝嗗尮閰嶄腑鎷彿瀛楃闆嗕腑鐨勬煇涓涓瓧絎? </p> <p><span id="hvzpftn" class="QUOTE">"[xyz]"</span> 灝嗕細鍖歸厤瀛楃<tt class="REPLACEABLE"><em>x</em></tt>, <tt class="REPLACEABLE"><em>y</em></tt>, 鎴?tt class="REPLACEABLE"><em>z</em></tt>. </p> <p><span id="hvzpftn" class="QUOTE">"[c-n]"</span> 鍖歸厤瀛楃<tt class="REPLACEABLE"><em>c</em></tt>鍒板瓧絎?tt class="REPLACEABLE"><em>n</em></tt>涔嬮棿鐨勪換鎰忎竴涓瓧絎? </p> <p><span id="hvzpftn" class="QUOTE">"[B-Pk-y]"</span> 鍖歸厤浠?tt class="REPLACEABLE"><em>B</em></tt>鍒?tt class="REPLACEABLE"><em>P</em></tt>, 鎴栬呬粠<tt class="REPLACEABLE"><em>k</em></tt>鍒?tt class="REPLACEABLE"><em>y</em></tt>涔嬮棿鐨勪換鎰忎竴涓瓧絎? </p> <p><span id="hvzpftn" class="QUOTE">"[a-z0-9]"</span> 鍖歸厤浠繪剰灝忓啓瀛楁瘝鎴栨暟瀛? </p> <p><span id="hvzpftn" class="QUOTE">"[^b-d]"</span> 灝嗕細鍖歸厤鑼冨洿鍦?tt class="REPLACEABLE"><em>b</em></tt>鍒?tt class="REPLACEABLE"><em>d</em></tt><em>涔嬪鐨?/em>浠繪剰涓涓瓧絎? 榪欏氨鏄嬌鐢?span class="TOKEN">^</span>瀵瑰瓧絎﹂泦鍙栧弽鐨勪竴涓疄渚? (灝卞ソ鍍忓湪鏌愪簺鎯呭喌涓? <span id="hvzpftn" class="TOKEN">!</span>鎵琛ㄨ揪鐨勫惈涔?. </p> <p>灝嗗涓腑鎷彿瀛楃闆嗙粍鍚堜嬌鐢? 鑳藉鍖歸厤涓鑸殑鍗曡瘝鎴栨暟瀛? <span id="hvzpftn" class="QUOTE">"[Yy][Ee][Ss]"</span>鑳藉鍖歸厤<tt class="REPLACEABLE"><em>yes</em></tt>, <tt class="REPLACEABLE"><em>Yes</em></tt>, <tt class="REPLACEABLE"><em>YES</em></tt>, <tt class="REPLACEABLE"><em>yEs</em></tt>, 絳夌瓑. <span id="hvzpftn" class="QUOTE">"[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]"</span> 鍙互鍖歸厤紺句繚鐮?Social Security number). </p></li> <li> <p>鍙嶆枩鏉?-- <span id="hvzpftn" class="TOKEN">\</span> -- 鐢ㄦ潵<a >杞箟</a>鏌愪釜鐗規畩鍚箟鐨勫瓧絎? 榪欐剰鍛崇潃, 榪欎釜鐗規畩瀛楃灝嗕細琚В閲婁負瀛楅潰鍚箟. </p> <p><span id="hvzpftn" class="QUOTE">"\$"</span>灝嗕細琚В閲婃垚瀛楃<span id="hvzpftn" class="QUOTE">"$"</span>, 鑰屼笉鏄疪E涓尮閰嶈灝劇殑鐗規畩瀛楃. 鐩鎬技鐨? <span id="hvzpftn" class="QUOTE">"\\"</span>灝嗕細琚В閲婁負瀛楃<span id="hvzpftn" class="QUOTE">"\"</span>. </p></li> <li> <p><a name="ANGLEBRAC"></a></p> <p><a >杞箟</a>鐨?span class="QUOTE">"灝栨嫭鍙?</span> -- <span id="hvzpftn" class="TOKEN">\<...\></span> -- 鐢ㄤ簬鍖歸厤鍗曡瘝杈圭晫. </p> <p>灝栨嫭鍙峰繀欏昏杞箟鎵嶅惈鏈夌壒孌婄殑鍚箟, 鍚﹀垯瀹冨氨琛ㄧず灝栨嫭鍙風殑瀛楅潰鍚箟. </p> <p><span id="hvzpftn" class="QUOTE">"\<the\>"</span> 瀹屾暣鍖歸厤鍗曡瘝<span id="hvzpftn" class="QUOTE">"the"</span>, 涓嶄細鍖歸厤<span id="hvzpftn" class="QUOTE">"them"</span>, <span id="hvzpftn" class="QUOTE">"there"</span>, <span id="hvzpftn" 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="hvzpftn" class="SIDEBAR"><a name="AEN13844"></a> <p>瑕佹兂紜畾涓涓猂E鑳藉惁姝e父宸ヤ綔, 鍞竴鐨勫姙娉曞氨鏄祴璇曞畠. </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. # 鍖歸厤.<br> 4  # 涓嶅尮閰?<br> 5  # 涓嶅尮閰?<br> 6 This line contains the number 113. # 鍖歸厤.<br> 7 This line contains the number 13. # 涓嶅尮閰?<br> 8 This line contains the number 133. # 涓嶅尮閰?<br> 9 This line contains the number 1133. # 鍖歸厤.<br> 10 This line contains the number 113312. # 鍖歸厤.<br> 11 This line contains the number 1112. # 涓嶅尮閰?<br> 12 This line contains the number 113312312. # 鍖歸厤.<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. # 鍖歸厤.<br> This line contains the number 113. # 鍖歸厤.<br> This line contains the number 1133. # 鍖歸厤.<br> This line contains the number 113312. # 鍖歸厤.<br> This line contains the number 113312312. # 鍖歸厤. </samp><br> </pre></font></td></tr></tbody></table></div></td></tr></tbody></table> <ul> <li style="LIST-STYLE-TYPE: square"> <div id="hvzpftn" class="FORMALPARA"> <p><strong><a name="EXTREGEX"></a>鎵╁睍鐨勬鍒欒〃杈懼紡. </strong>娣誨姞浜嗕竴浜涢澶栫殑鍖歸厤瀛楃鍒板熀鏈泦鍚堜腑. 鐢ㄤ簬<a >egrep</a>, <a >awk</a>, 鍜?a >Perl</a>.</p></div></li> <li> <p><a name="QUEXREGEX"></a></p> <p>闂彿 -- <span id="hvzpftn" class="TOKEN">?</span> -- 鍖歸厤瀹冨墠闈㈢殑瀛楃, 浣嗘槸鍙兘鍖歸厤1嬈℃垨0嬈? 閫氬父鐢ㄦ潵鍖歸厤鍗曚釜瀛楃. </p></li> <li> <p><a name="PLUSREF"></a></p> <p>鍔犲彿 -- <span id="hvzpftn" class="TOKEN">+</span> -- 鍖歸厤瀹冨墠闈㈢殑瀛楃, 鑳藉鍖歸厤涓嬈℃垨澶氭. 涓庡墠闈㈣鐨?span class="TOKEN">*</span>鍙蜂綔鐢ㄧ被浼? 浣嗘槸<em>涓嶈兘</em>鍖歸厤0涓瓧絎︾殑鎯呭喌. </p> <table style="width: 558px; height: 209px; " border="0" bgcolor="#e0e0e0"> <tbody> <tr> <td><font color="#000000"><pre class="PROGRAMLISTING"> 1 # GNU鐗堟湰鐨剆ed鍜宎wk鑳藉浣跨敤"+",<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="hvzpftn" class="QUOTE">"澶ф嫭鍙?</span> -- <span id="hvzpftn" class="TOKEN">\{ \}</span> -- 鍦ㄨ漿涔夊悗鐨勫ぇ鎷彿涓姞涓婁竴涓暟瀛? 榪欎釜鏁板瓧灝辨槸瀹冨墠闈㈢殑RE鎵鑳藉尮閰嶇殑嬈℃暟. </p> <p>澶ф嫭鍙峰繀欏葷粡榪囪漿涔? 鍚﹀垯, 澶ф嫭鍙蜂粎浠呰〃紺哄瓧闈㈠惈鎰? 榪欑鐢ㄦ硶騫朵笉鏄熀鏈琑E闆嗗悎涓殑涓閮ㄥ垎, 浠呬粎鏄釜鎶宸ц屼互. </p> <p><span id="hvzpftn" class="QUOTE">"[0-9]\{5\}"</span> 綺劇‘鍖歸厤5涓暟瀛?(鎵鍖歸厤鐨勫瓧絎﹁寖鍥存槸0鍒?). </p> <div id="hvzpftn" class="NOTE"> <table class="NOTE" border="0" width="90%"> <tbody> <tr> <td valign="top" width="25" align="middle"><img hspace="5" alt="Note" src="file:///D:/users/kenwell/Desktop/Linux%20Shell%20Bash%20%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BB%8B%E7%BB%8D%20-%20Powered%20by%20PHPWind.net_files/2452689_1.gif"></td> <td valign="top" align="left"> <p>浣跨敤澶ф嫭鍙峰艦寮忕殑RE鏄笉鑳藉鍦?span class="QUOTE">"緇忓吀"</span>(闈濸OSIX鍏煎)鐨?a >awk</a>鐗堟湰涓甯歌繍琛岀殑. 鐒惰? <strong class="COMMAND">gawk</strong>鍛戒護涓湁涓涓?code class="OPTION">--re-interval</code>閫夐」, 浣跨敤榪欎釜閫夐」灝卞厑璁鎬嬌鐢ㄥぇ鎷彿褰㈠紡鐨凴E浜?鏃犻渶杞箟). </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> -- 鎷搗涓緇勬鍒欒〃杈懼紡. 褰撲綘鎯充嬌鐢?a >expr</a>榪涜<a >瀛愬瓧絎︿覆鎻愬彇(substring extraction)</a>鐨勬椂鍊? 鍦嗘嫭鍙峰氨鏈夌敤浜? 濡傛灉鍜屼笅闈㈣璁茬殑<span id="hvzpftn" class="QUOTE">"<span id="hvzpftn" class="TOKEN">|</span>"</span>鎿嶄綔絎︾粨鍚堜嬌鐢? 涔熼潪甯告湁鐢? </p></li> <li> <p>绔栫嚎 -- <strong class="COMMAND">|</strong> -- 灝辨槸RE涓殑<span id="hvzpftn" class="QUOTE">"鎴?</span>鎿嶄綔絎? 浣跨敤瀹冭兘澶熷尮閰嶄竴緇勫彲閫夊瓧絎︿腑鐨勪換鎰忎竴涓? </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="hvzpftn" 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>涓嶨NU宸ュ叿涓鏍? 鏌愪簺鐗堟湰鐨?strong class="COMMAND">sed</strong>, <strong class="COMMAND">ed</strong>, 鍜?strong class="COMMAND">ex</strong>涓鏍瘋兘澶熸敮鎸佹墿灞曟鍒欒〃杈懼紡, 涓婅竟榪欓儴鍒嗗氨鎻忚堪浜嗘墿灞曟鍒欒〃杈懼紡. </p></td></tr></tbody></table></div> <ul> <li style="LIST-STYLE-TYPE: square"> <div id="hvzpftn" class="FORMALPARA"> <p><strong><a name="POSIXREF"></a>POSIX瀛楃綾? </strong><kbd class="USERINPUT">[:class:]</kbd></p></div> <p>榪欐槸鍙﹀涓縐? 鐢ㄤ簬鎸囧畾鍖歸厤瀛楃鑼冨洿鐨勬柟娉? </p></li> <li> <p><kbd class="USERINPUT">[:alnum:]</kbd> 鍖歸厤瀛楁瘝鍜屾暟瀛? 絳変環浜?kbd class="USERINPUT">A-Za-z0-9</kbd>. </p></li> <li> <p><kbd class="USERINPUT">[:alpha:]</kbd> 鍖歸厤瀛楁瘝. 絳変環浜?kbd class="USERINPUT">A-Za-z</kbd>. </p></li> <li> <p><kbd class="USERINPUT">[:blank:]</kbd> 鍖歸厤涓涓┖鏍兼垨鏄竴涓埗琛ㄧ(tab). </p></li> <li> <p><kbd class="USERINPUT">[:cntrl:]</kbd> 鍖歸厤鎺у埗瀛楃. </p></li> <li> <p><kbd class="USERINPUT">[:digit:]</kbd> 鍖歸厤(鍗佽繘鍒?鏁板瓧. 絳変環浜?kbd class="USERINPUT">0-9</kbd>. </p></li> <li> <p><kbd class="USERINPUT">[:graph:]</kbd> (鍙墦鍗扮殑鍥懼艦瀛楃). 鍖歸厤ASCII鐮佸艱寖鍥村湪33 - 126涔嬮棿鐨勫瓧絎? 涓庝笅闈㈡墍鎻愬埌鐨?kbd class="USERINPUT">[:print:]</kbd>綾諱技, 浣嗘槸涓嶅寘鎷┖鏍煎瓧絎?絀烘牸瀛楃鐨凙SCII鐮佹槸32). </p></li> <li> <p><kbd class="USERINPUT">[:lower:]</kbd> 鍖歸厤灝忓啓瀛楁瘝. 絳変環浜?kbd class="USERINPUT">a-z</kbd>. </p></li> <li> <p><kbd class="USERINPUT">[:print:]</kbd> (鍙墦鍗扮殑鍥懼艦瀛楃). 鍖歸厤ASCII鐮佸艱寖鍥村湪32 - 126涔嬮棿鐨勫瓧絎? 涓庝笂杈圭殑<kbd class="USERINPUT">[:graph:]</kbd>綾諱技, 浣嗘槸鍖呭惈絀烘牸. </p></li> <li> <p><kbd class="USERINPUT">[:space:]</kbd> 鍖歸厤絀虹櫧瀛楃(絀烘牸鍜屾按騫沖埗琛ㄧ). </p></li> <li> <p><kbd class="USERINPUT">[:upper:]</kbd> 鍖歸厤澶у啓瀛楁瘝. 絳変環浜?kbd class="USERINPUT">A-Z</kbd>. </p></li> <li> <p><kbd class="USERINPUT">[:xdigit:]</kbd> 鍖歸厤16榪涘埗鏁板瓧. 絳変環浜?kbd class="USERINPUT">0-9A-Fa-f</kbd>. </p> <div id="hvzpftn" class="IMPORTANT"> <table class="IMPORTANT" border="0" width="90%"> <tbody> <tr> <td valign="top" width="25" align="middle"><img hspace="5" alt="Important" src="file:///D:/users/kenwell/Desktop/Linux%20Shell%20Bash%20%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BB%8B%E7%BB%8D%20-%20Powered%20by%20PHPWind.net_files/2452689_2.gif"></td> <td valign="top" align="left"> <p>POSIX瀛楃綾婚氬父閮借鐢ㄥ紩鍙鋒垨<a >鍙屼腑鎷彿</a>([[ ]])寮曡搗鏉? </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>濡傛灉鍦ㄤ竴涓彈闄愮殑鑼冨洿鍐? 榪欎簺瀛楃綾葷敋鑷沖彲浠ョ敤鍦?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>濡傛灉鎯充簡瑙OSIX瀛楃綾誨湪鑴氭湰涓殑浣跨敤鎯呭喌, 璇峰弬鑰?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>鍦ㄨ剼鏈腑涓鑸兘琚敤浣滆繃婊ゅ櫒, 榪欎簺榪囨護鍣ㄥ皢浼氫互RE涓哄弬鏁? 瀵規枃浠舵垨鑰匢/O嫻佽繘琛?榪囨護"鎴栬漿鎹? 璇峰弬鑰?a >渚嬪瓙 A-12</a>鍜?a >渚嬪瓙 A-17</a>, 鏉ヨ緇嗕簡瑙h繖縐嶇敤娉? </p> <p>瀵逛簬RE榪欎釜澶嶆潅鐨勪富棰? 鏍囧噯鐨勫弬鑰冩潗鏂欐槸Friedl鐨?em class="CITETITLE">Mastering Regular Expressions</em>. 鐢盌ougherty鍜孯obbins鎵緙栧啓鐨?em class="CITETITLE">Sed & Awk</em>榪欐湰涔? 涔熷RE榪涜浜嗘竻鏅扮殑璁鴻堪. 濡傛灉鎯寵幏寰楄繖浜涗功鐨勬洿澶氫俊鎭? 璇峰療鐪?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="hvzpftn" class="footnote">[1]</span></a></td> <td valign="top" width="95%" align="left"> <p>鍥犱負<a >sed</a>, <a >awk</a>, 鍜?a >grep</a>閫氬父鐢ㄤ簬澶勭悊鍗曡, 浣嗘槸涓嶈兘鍖歸厤涓涓崲琛岀. 濡傛灉浣犳兂澶勭悊澶氳杈撳叆鐨勮瘽, 閭d箞浣犲彲浠ヤ嬌鐢?鐐?鏉ュ尮閰嶆崲琛岀. </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++ 瀛︿範</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++ 瀛︿範</dc:creator><author>c++ 瀛︿範</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:瀹嬩綋;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:瀹嬩綋;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:瀹嬩綋;color:black;mso-font-kerning:0pt">expr</span><span style="font-size:13.5pt;font-family:瀹嬩綋;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: 瀹嬩綋;color:black;mso-font-kerning:0pt">,</span><span style="font-size:13.5pt; font-family:瀹嬩綋;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:瀹嬩綋;mso-bidi-font-family:瀹嬩綋;mso-font-kerning:0pt"><o:p></o:p></span></p> <p class="MsoNormal" align="left" style="text-align:left;mso-pagination:widow-orphan; background:white"><span lang="EN-US" style="font-size:8.0pt;mso-bidi-font-size: 11.0pt;font-family:"Courier New";mso-fareast-font-family:瀹嬩綋;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:瀹嬩綋;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: 瀹嬩綋;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:瀹嬩綋;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:瀹嬩綋;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:瀹嬩綋;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: 瀹嬩綋;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:瀹嬩綋;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: 瀹嬩綋;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:瀹嬩綋;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:瀹嬩綋;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: 瀹嬩綋;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:瀹嬩綋;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:瀹嬩綋;color:black; mso-font-kerning:0pt"><o:p></o:p></span></strong></p> <p class="MsoNormal"><span lang="EN-US">let </span><span style="font-family:瀹嬩綋; mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family: 瀹嬩綋;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin">鐨勪嬌鐢ㄦ柟寮?/span></p> <p class="MsoNormal"><span lang="EN-US">x=10</span></p> <p class="MsoNormal"><span lang="EN-US">let x=$x+1</span></p> <p class="MsoNormal"><span lang="EN-US">let x+=1</span></p> <p class="MsoNormal"><span lang="EN-US">let x*=10</span></p> <p class="MsoNormal"><span style="font-family:瀹嬩綋;mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:瀹嬩綋;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">絳?/span></p> <p class="MsoNormal"><span lang="EN-US">Let</span><span style="font-family:瀹嬩綋; mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family: 瀹嬩綋;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin">娌℃湁榪斿洖鍊?/span></p> <p class="MsoListParagraph" align="left" style="margin-left:21.0pt;text-align:left; text-indent:-21.0pt;mso-char-indent-count:0;mso-pagination:widow-orphan; mso-list:l0 level1 lfo1"><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="font-size:13.5pt;font-family:"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:瀹嬩綋;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: 瀹嬩綋;color:black;mso-font-kerning:0pt">$((expression ))</span></strong><strong style="mso-bidi-font-weight:normal"><span style="font-size:13.5pt;mso-bidi-font-size: 11.0pt;font-family:瀹嬩綋;mso-ascii-font-family:"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:瀹嬩綋;color:black;mso-font-kerning:0pt">((expression))</span></strong><strong style="mso-bidi-font-weight:normal"><span style="font-size:13.5pt;mso-bidi-font-size: 11.0pt;font-family:瀹嬩綋;mso-ascii-font-family:"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:瀹嬩綋;color:black;mso-font-kerning:0pt"><o:p></o:p></span></strong></p> <p class="MsoNormal"><span lang="EN-US">((expression))</span><span style="font-family:瀹嬩綋;mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin; mso-fareast-font-family:瀹嬩綋;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: Calibri;mso-hansi-theme-font:minor-latin">鐨勪嬌鐢ㄦ柟娉?/span></p> <p class="MsoNormal"><span lang="EN-US">x=10</span></p> <p class="MsoNormal"><span lang="EN-US">((x+=10))</span></p> <p class="MsoNormal"><span lang="EN-US">(( expression)) </span><span style="font-family:瀹嬩綋;mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin; mso-fareast-font-family:瀹嬩綋;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: Calibri;mso-hansi-theme-font:minor-latin">鐢ㄦ硶鍜?/span><span lang="EN-US">let</span><span style="font-family:瀹嬩綋;mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin; mso-fareast-font-family:瀹嬩綋;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: Calibri;mso-hansi-theme-font:minor-latin">綾諱技</span></p> <p class="MsoNormal"><span lang="EN-US">$(())</span><span style="font-family:瀹嬩綋; mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family: 瀹嬩綋;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin">鐨勪嬌鐢ㄧ敤娉?/span></p> <p class="MsoNormal"><span style="font-family:瀹嬩綋;mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:瀹嬩綋;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">錛?/span><span lang="EN-US"> $((x=$x+10))</span></p> <p class="MsoNormal"><span lang="EN-US">echo $x</span></p> <p class="MsoNormal"><span lang="EN-US">y=$((x=$x-10))</span></p> <p class="MsoNormal"><span lang="EN-US">echo $y</span></p> <p class="MsoNormal"><span lang="EN-US">y=$(($x+1))</span></p> <p class="MsoNormal"><span lang="EN-US">echo $y</span></p> <p class="MsoNormal"><span lang="EN-US">echo $x</span></p> <p class="MsoNormal"><span lang="EN-US"><o:p> </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:瀹嬩綋;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: 瀹嬩綋;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:瀹嬩綋;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:瀹嬩綋;color:black; mso-font-kerning:0pt"><o:p></o:p></span></strong></p> <p class="MsoNormal"><span style="font-family:瀹嬩綋;mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:瀹嬩綋;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">渚嬪錛?/span></p> <p class="MsoNormal"><span lang="EN-US">n=1</span></p> <p class="MsoNormal"><span lang="EN-US">:<span style="mso-spacerun:yes">  </span>$[ n=$n+1 ](</span><span style="font-family:瀹嬩綋;mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:瀹嬩綋;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">錛氬拰</span><span lang="EN-US">$</span><span style="font-family:瀹嬩綋;mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:瀹嬩綋;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">涔嬮棿鏈夌┖鏍?/span><span lang="EN-US">)</span></p> <p class="MsoNormal"><span lang="EN-US">y=$[ n = $n + 1 ]</span></p> <p class="MsoNormal"><span lang="EN-US">echo $y</span></p> <p class="MsoNormal"><span lang="EN-US">y=$[ $n+1 ]</span></p> <p class="MsoNormal"><span lang="EN-US">echo $y</span></p> <p class="MsoNormal"><span lang="EN-US"><o:p> </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:瀹嬩綋;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: 瀹嬩綋;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: 瀹嬩綋;color:black;mso-font-kerning:0pt"><o:p></o:p></span></strong></p> <p class="MsoNormal"><span style="font-family:瀹嬩綋;mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:瀹嬩綋;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">渚嬪瓙錛?/span></p> <p class="MsoNormal"><span lang="EN-US">decare –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++ 瀛︿範</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 榪涚▼鏇挎崲錛?/title><link>http://m.shnenglu.com/kenwell/archive/2010/06/27/118826.html</link><dc:creator>c++ 瀛︿範</dc:creator><author>c++ 瀛︿範</author><pubDate>Sun, 27 Jun 2010 09:15:00 GMT</pubDate><guid>http://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="hvzpftn" 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="hvzpftn" id="content-area" style="padding-bottom: 20px; "><div class="hvzpftn" id="node-1006985" class="node node-type-story" style="margin-top: 1em; margin-right: 1em; margin-bottom: 1em; margin-left: 1em; "><div id="hvzpftn" class="node-inner"><div id="hvzpftn" class="meta" style="font-size: 0.9em; margin-top: 0.1em; "><div id="hvzpftn" 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="hvzpftn" 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="hvzpftn" 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="hvzpftn" 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>榪涚▼鏇挎崲涓庡懡浠ゆ浛鎹㈠緢鐩鎬技. 鍛戒護鏇挎崲鎶婁竴涓懡浠ょ殑緇撴灉璧嬪肩粰涓涓彉閲? 姣斿dir_contents=`ls -</p><p>al`鎴杧ref=$( grep word datafile). 榪涚▼鏇挎崲鎶婁竴涓繘紼嬬殑杈撳嚭鎻愪緵緇欏彟涓涓繘紼?鎹㈠彞璇濊, 瀹冩妸</p><p>涓涓懡浠ょ殑緇撴灉鍙戠粰浜嗗彟涓涓懡浠?.</p><p>鍛戒護鏇挎崲鐨勬ā鐗?/p><p>鐢ㄥ渾鎷彿鎵╄搗鏉ョ殑鍛戒護</p><p>>(command)</p><p><(command)</p><p>鍚姩榪涚▼鏇挎崲. 瀹冧嬌鐢?dev/fd/<n>鏂囦歡灝嗗渾鎷彿涓殑榪涚▼澶勭悊緇撴灉鍙戦佺粰鍙︿竴涓繘紼? [1] (璇?/p><p>鑰呮敞: 瀹為檯涓婄幇浠g殑UNIX綾繪搷浣滅郴緇熸彁渚涚殑/dev/fd/n鏂囦歡鏄笌鏂囦歡鎻忚堪絎︾浉鍏崇殑, 鏁存暟n鎸囩殑灝?/p><p>鏄繘紼嬭繍琛屾椂瀵瑰簲鏁板瓧鐨勬枃浠舵弿榪扮)</p><p>鍦?<"鎴?>"涓庡渾鎷彿涔嬮棿鏄病鏈夌┖鏍肩殑. 濡傛灉鍔犱簡絀烘牸, 浼氫駭鐢熼敊璇?</p><p>bash$ echo >(true)</p><p>/dev/fd/63</p><p>bash$ echo <(true)</p><p>/dev/fd/63</p><p>Bash鍦ㄤ袱涓枃浠舵弿榪扮涔嬮棿鍒涘緩浜嗕竴涓閬? --fIn鍜宖Out--. true鍛戒護鐨剆tdin琚繛鎺ュ埌fOut</p><p>(dup2(fOut, 0)), 鐒跺悗Bash鎶?dev/fd/fIn浣滀負鍙傛暟浼犵粰echo. 濡傛灉緋葷粺緙轟箯/dev/fd/<n>鏂囦歡, Bash浼?/p><p>浣跨敤涓存椂鏂囦歡. (鎰熻阿, S.C.)</p><p>榪涚▼鏇挎崲鍙互姣旇緝涓や釜涓嶅悓鍛戒護鐨勮緭鍑? 鐢氳嚦鑳藉姣旇緝鍚屼竴涓懡浠や笉鍚岄夐」鎯呭喌涓嬬殑杈撳嚭.</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>浣跨敤榪涚▼鏇挎崲鏉ユ瘮杈冧袱涓笉鍚岀洰褰曠殑鍐呭(鍙互鏌ョ湅鍝簺鏂囦歡鍚嶇浉鍚? 鍝簺鏂囦歡鍚嶄笉鍚?:</p><p>1 diff <(ls $first_directory) <(ls $second_directory)</p><p>涓浜涜繘紼嬫浛鎹㈢殑鍏朵粬鐢ㄦ硶涓庢妧宸?</p><p>1 cat <(ls -l)</p><p>2 # 絳変環浜?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 # 鍒楀嚭緋葷粺3涓富瑕?bin'鐩綍涓殑鎵鏈夋枃浠? 騫朵笖鎸夋枃浠跺悕榪涜鎺掑簭.</p><p>6 # 娉ㄦ剰鏄?涓?鏌ヤ竴涓? 涓婇潰灝?涓渾鎷彿)鏄庢樉涓嶅悓鐨勫懡浠よ緭鍑轟紶閫掔粰'sort'.</p><p>7</p><p>8</p><p>9 diff <(command1) <(command2) # 緇欏嚭涓や釜鍛戒護杈撳嚭鐨勪笉鍚屼箣澶?</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 # 鍥犱負/dev/fd/<n>鐨勭郴緇熷睘鎬?</p><p>15 # 鎵浠ヤ袱涓懡浠や箣闂寸殑綆¢亾涓嶅繀琚懡鍚?</p><p>16 #</p><p>17 # 榪欑鏁堟灉鍙互琚ā鎷熷嚭鏉?</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>涓涓鑰呯粰鎴戝彂浜嗕竴涓湁瓚g殑渚嬪瓙, 鏄叧浜庤繘紼嬫浛鎹㈢殑, 濡備笅.</p><p>1 # 鎽樿嚜SuSE鍙戣鐗堜腑鐨勪唬鐮佺墖鏂?</p><p>2</p><p>3 while read des what mask iface; do</p><p>4 # 榪欓噷鐪佺暐浜嗕竴浜涘懡浠?..</p><p>5 done < <(route -n)</p><p>6</p><p>7</p><p>8 # 涓轟簡嫻嬭瘯瀹? 鎴戜滑璁╁畠鍋氱偣浜?</p><p>9 while read des what mask iface; do</p><p>10 echo $des $what $mask $iface</p><p>11 done < <(route -n)</p><p>12</p><p>13 # 杈撳嚭:</p><p>14 # Kernel IP routing table</p><p>15 # Destination Gateway Genmask Flags Metric Ref Use Iface</p><p>16 # 127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo</p><p>17</p><p>18</p><p>19</p><p>20 # 灝卞儚Stephane Chazelas鎵緇欏嚭鐨勯偅鏍? 涓涓洿瀹規槗鐞嗚В鐨勭瓑浠蜂唬鐮佹槸:</p><p>21 route -n |</p><p>22 while read des what mask iface; do # 綆¢亾鐨勮緭鍑鴻璧嬪肩粰浜嗗彉閲?</p><p>23 echo $des $what $mask $iface</p><p>24 done # 榪欏皢浜х敓鍑轟笌涓婅竟鐩稿悓鐨勮緭鍑?</p><p>25 # 鐒惰? Ulrich Gayer鎸囧嚭 . . .</p><p>26 #+ 榪欎釜綆鍗曠殑絳変環鐗堟湰鍦╳hile寰幆涓嬌鐢ㄤ簡涓涓瓙shell,</p><p>27 #+ 鍥犳褰撶閬撶粨鏉熷悗, 鍙橀噺灝辨秷澶變簡.</p><p>28</p><p>29</p><p>30</p><p>31 # 鏇磋繘涓姝? Filip Moritz瑙i噴浜嗕笂闈袱涓緥瀛愪箣闂村瓨鍦ㄤ竴涓粏寰殑涓嶅悓涔嬪,</p><p>32 #+ 濡備笅鎵紺?</p><p>33</p><p>34 (</p><p>35 route -n | while read x; do ((y++)); done</p><p>36 echo $y # $y 浠嶇劧娌℃湁琚0鏄庢垨璁劇疆</p><p>37</p><p>38 while read x; do ((y++)); done < <(route -n)</p><p>39 echo $y # $y 鐨勫間負route -n鐨勮緭鍑鴻鏁?</p><p>40 )</p><p>41</p><p>42 # 涓鑸潵璇? (璇戣呮敞: 鍘熶功浣滆呭湪榪欓噷騫舵湭鍔犳敞閲婄鍙?#", 搴旇鏄瑪璇?</p><p>43 (</p><p>44 : | x=x</p><p>45 # 鐪嬩笂鍘繪槸鍚姩浜嗕竴涓瓙shell</p><p>46 : | ( x=x )</p><p>47 # 浣?/p><p>48 x=x < <(:)</p><p>49 # 鍏跺疄涓嶆槸</p><p>50 )</p><p>51</p><p>52 # 褰撲綘瑕佽В鏋恈sv鎴栫被浼間笢瑗跨殑鏃朵警, 榪欓潪甯告湁鐢?</p><p>53 # 浜嬪疄涓? 榪欏氨鏄疭uSE鐨勮繖涓唬鐮佺墖鏂墍瑕佸疄鐜扮殑鍔熻兘.</p><p>娉ㄦ剰浜嬮」</p><p>[1] 榪欎笌鍛藉悕綆¢亾(涓存椂鏂囦歡)鍏鋒湁鐩稿悓鐨勪綔鐢? 騫朵笖, 浜嬪疄涓? 鍛藉悕綆¢亾涔熻鍚屾椂浣跨敤鍦ㄨ繘紼?/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++ 瀛︿範</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鐨勭閬撲笌榪涚▼鐨勫嚑涓煡璇嗙偣http://m.shnenglu.com/kenwell/archive/2010/06/25/118723.htmlc++ 瀛︿範c++ 瀛︿範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鍦ㄥ疄鐜皃ipeline(綆¢亾|)鏃朵細鍙戣搗涓や釜subshell(瀛恠hell)鏉ヨ繍琛寍涓よ竟鐨?span href="tag.php?name=%C3%FC%C1%EE" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 0, 0); white-space: nowrap; ">鍛戒護錛屽浜?span 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; ">緋葷粺鏉ヨ灝辨槸鍙戣搗涓や釜childprocess(瀛愯繘紼嬶級

2.fork鏄駭鐢焢rocess鐨勫敮涓閫斿緞錛宔xec*鏄墽琛岀▼搴忕殑鍞竴閫斿緞

3.瀛愯繘紼嬩細瀹屽叏澶嶅埗鐖惰繘紼嬶紝闄や簡$PID涓?PPID

4.fork瀛愯繘紼嬫椂緇ф壙鐖惰繘紼嬬殑榪涚▼鍚嶏紝鍦╡xec*鎵ц鍛戒護鏃舵墠鐢眅xec*鏇挎崲涓哄瓙榪涚▼瀵瑰簲鐨勫懡浠わ紝鍚屼竴榪涚▼鐨勫懡浠ゅ悕鍙互鐢變竴涓釜exec*浠繪剰澶氭鐨勬敼鍙?/strong>



[娉╙瀵逛簬linux騫沖彴錛孞B涓婂氨鏄繖鏍風殑錛屽叾瀹冨鉤鍙頒笉濂藉彂琛ㄦ剰瑙侊紝褰撶劧瀵逛簬2涓殑涓や釜鍞竴鏈変竴涓緥澶栵紝灝辨槸鍦╧enerl  init鐨勫垵鏈?
鏆傛椂鎵句笉鍒扮浉鍏沖弬鑰冿紝涔熸病鏈夊姛鍔涜婧愮爜錛屾墍浠ユ璁烘槸閬撳惉閫旇綰у埆錛岄敊璇箣澶勮鎸囧嚭鏀規錛屽鏋滄病鏈夋敼姝g殑浠峰煎彲涓絎戣岃繃

鎴戣寰楄鍏堝紕娓呮sub shell鐨勫畾涔夈?br style="word-wrap: break-word; line-height: normal; ">
鏌ヤ簡浜涜祫鏂欙紝鍙戠幇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.



榪欎釜separate execution鏄痵ubshell鍚楋紵
A. 鍦ㄥ綋鍓峴hell鎵ц澶栭儴鍛戒護錛屽shell> date, 鏄痜ork+exec, 綆椾笉鏄痵ubshell? 
B. ()鏄痜ork涓涓猚hild shell錛岃child鍐峟ork+exec鏉ユ墽琛屽懡浠ゃ傝繖涓猻ubshell鍜孉涓殑"subshell"鏄劇劧鏄笉鍚岀殑銆?br style="word-wrap: break-word; line-height: normal; ">
UNIX: The Textbook, by Syed Mansoor Sarvar, Robert Koretsky and Syed Aqeel Sarvar涓彁鍒幫細


QUOTE:
A child shell is also called subshell


闂鏄痜ork+exec鏄痜ork涓涓猚hild shell錛岀劧鍚庡湪璇hild shell涓璭xec.
鑰屾墽琛岃剼鏈?shell>scriptname)鏃訛紝鏄痜ort涓涓猚hild shell A錛岃child shell A鍐峟ork涓涓猚hild shell B, 鍦˙涓啀exec.

閭d箞child shell鏄寚鍝鎯呭喌錛?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.


澶栭儴鍛戒護涔熷湪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-inCommands榪欐牱鎵ц鏃訛紝澶ч儴鍒嗗唴閮ㄥ懡浠や篃鏄湪subshell涓墽琛屻?br style="word-wrap: break-word; line-height: normal; ">鍙錛孶NIX at Fermilab璁や負fork 涓涓猚hild shell灝辨槸subshell, 涓嶇鏄痜ork-fork+exec, 榪樻槸 fork+exec銆?br>
鎴戝垰鎵嶅張鍘葷炕浜嗕笅ABS錛屽畾涔変笌鎴戠殑鐞嗚В涓嶄竴鏍?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鐨勪竴縐嶅晩錛岄兘鏄痜ork-exec錛岃嚦浜巈xternal-cmd鍐嶄綔浠涔堝姩浣滃畬鍏ㄦ槸external-cmd鐨?/td>



]]>
shell metacharacters 涓嶪FS璁ㄨhttp://m.shnenglu.com/kenwell/archive/2010/06/25/118721.htmlc++ 瀛︿範c++ 瀛︿範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!
綹界畻鏈変漢鐪嬪緱鎳備簡銆?/span>

涓嶉亷錛岃绱拌鐨勮┍錛岃鎵笂 shell 鍦?interpret 涓鍊?command line 鏅傜殑 priority 銆?/span>
鍩烘湰涓婏紝鍏墮爢搴忓涓嬶細
1錛屽皣 line 鎷嗘垚 words 錛圛FS寰堥噸瑕侊級
2錛屾嫭灞?alias
3錛屾摯灞?锝?锝?/span>
4錛屾摯灞?~
5錛屾摯灞?$variable, $(command), `command`
6錛岄噸緄勫啀鎷嗘垚 words
7錛屾嫭灞?wildcards
8錛岃檿鐞?I/O redirection
9錛岃級鍏ュ懡浠ら亱琛?/span>
濡傛灉澶у鏈塐'Reilly鑻辨枃鐗堢殑 Learning the Bash(2nd)鐨勮┍錛岃珛澶氱瑭硃178鐨勫湒錛堢窗綃鐣ョ暟錛?/span>

鍥炲埌LZ鐨勫晱欏岋紝鐪嬩笂闈?5 璺?6 鐨勯爢搴忕劧寰屾墠鏄?9 銆?/span>
涔熷氨鏄湪 6 閲嶇祫鍛戒護鏅?$A 宸茬稉瀹屾垚鏇挎彌錛岀暥鏅傜殑 environment 鏄矑璩﹀鹼紝
鍥犳閲嶇祫寰屽氨鏄?A=B echo
鐒跺緦鍦ㄧ 9 鐨勬椹熼亱琛屽懡浠ゆ檪錛?A=B 鏄鄲 echo 鍛戒護鐨?local environment錛?/span>
涓嶇鏄惁 built-in command錛岄兘涓嶅獎闊跨暥鍓嶇殑 shell 錛堜笉鍚岀殑 shell 鍦ㄥ浣滀笂鎴栨湁宸暟錛?/span>
鎵浠ョ浜岃鐨?echo $A 涔熸槸寰楀埌娌掕腸鍊?/span>
鎴戦氳繃eval璇存槑璧嬪兼槸鎴愬姛鐨勶紝鑰屼笉鏄?5妤兼墍璇寸殑璧嬪間笉鎴愬姛銆?br style="word-wrap: break-word; line-height: normal; ">
絎竴姝ヤ嬌鐢?metacharacter錛屼笌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 鍛戒護琛岀殑璇勪環錛坋valuation錛?br style="word-wrap: break-word; line-height: normal; ">涓嬮潰鏄疌 shell 瑙i噴鍛戒護琛岀殑欏哄簭錛?br style="word-wrap: break-word; line-height: normal; ">1. 鍘嗗彶鏇挎崲
2. 鍒嗚璇嶏紙鍖呮嫭鐗規畩瀛楃錛?br style="word-wrap: break-word; line-height: normal; ">3. 鏇存柊鍘嗗彶琛?br style="word-wrap: break-word; line-height: normal; ">4. 瑙i噴鍗曞紩鍙鳳紙'錛?鍜?鍙屽紩鍙鳳紙"錛?br style="word-wrap: break-word; line-height: normal; ">5. 鍒悕鏇挎崲
6. 杈撳叆鍜岃緭鍑虹殑閲嶅畾鍚戯紙濡?>  < 鍜?|錛?br style="word-wrap: break-word; line-height: normal; ">7. 鍙橀噺鏇挎崲
8. 鍛戒護鏇挎崲
9. 鏂囦歡鍚嶆墿灞?br style="word-wrap: break-word; line-height: normal; ">錛圔ourne shell 鐨勮В閲婇『搴忔湰璐ㄤ笂鏄竴鏍風殑錛岄櫎浜嗗畠涓嶆墽琛屽巻鍙叉浛鎹㈠拰鍒悕鏇挎崲涔嬪錛?br style="word-wrap: break-word; line-height: normal; ">
鎵浠?br style="word-wrap: break-word; line-height: normal; ">A=B  echo    $A

鐨勬墽琛岃繃紼嬪簲璇ユ槸榪欐牱鐨勶細
1. 娌℃湁鍘嗗彶鎿嶄綔絎︼紝 鍥犳涓嶈繘琛屽巻鍙叉浛鎹紙Bourne shell 涓嶆墽琛岃繖涓姝ワ級
2. 鍒嗚璇嶏紝姣忕鍒版湭鍔犲紩鍙風殑絀虹櫧瀛楃灝變細浜х敓涓涓柊“璇?#8221;銆傝繖浜涜瘝鏄?A=B銆乪cho銆?A銆?br style="word-wrap: break-word; line-height: normal; ">3. shell 灝嗗懡浠よ鏀懼埌鍘嗗彶鍒楄〃涓傦紙Bourne shell 涓嶆墽琛岃繖涓姝ワ級
4. 娌℃湁寮曞彿闇瑕佽В閲?br style="word-wrap: break-word; line-height: normal; ">5. 娌℃湁鍒悕闇瑕佹浛鎹?br style="word-wrap: break-word; line-height: normal; ">6. 娌℃湁杈撳叆鎴栬緭鍑洪噸瀹氬悜闇瑕佸鐞?br style="word-wrap: break-word; line-height: normal; ">7. shell娉ㄦ剰鍒板彉閲?A錛屽茍鎶婂畠鏇挎崲鎴愮┖
8. shell瀵繪壘宸﹀崟寮曞彿錛屾墽琛屽乏鍗曞紩鍙蜂腑鐨勪換浣曞懡浠わ紝騫朵笖灝嗗懡浠ょ殑杈撳嚭鎻掑叆鍒板懡浠よ涓傚湪鏈緥涓紝娌℃湁榪欐柟闈㈢殑浜嬮渶瑕佸仛銆傦紙濡傛灉宸﹀崟寮曞彿鍐呮湁閫氶厤絎︽垨鑰呭彉閲忥紝閭d箞鍦╯hell榪愯宸﹀崟寮曞彿涓殑鍛戒護涔嬪墠瀹冧滑鏄笉浼氳瑙i噴鐨勶級
9. shell瀵繪壘閫氶厤絎︺傛湰渚嬩腑娌℃湁錛屼笉闇瑕佸鐞?br style="word-wrap: break-word; line-height: normal; ">10. shell 鎵ц A=B錛?鎵ц echo 銆?/span>
8.05 鍛戒護琛岀殑璇勪環錛坋valuation錛?br style="word-wrap: break-word; line-height: normal; ">涓嬮潰鏄疌 shell 瑙i噴鍛戒護琛岀殑欏哄簭錛?br style="word-wrap: break-word; line-height: normal; ">1. 鍘嗗彶鏇挎崲
2. 鍒嗚璇嶏紙鍖呮嫭鐗規畩瀛楃錛?br style="word-wrap: break-word; line-height: normal; ">3. 鏇存柊鍘嗗彶琛?br style="word-wrap: break-word; line-height: normal; ">4. 瑙i噴鍗曞紩鍙鳳紙'錛?鍜?鍙屽紩鍙鳳紙"錛?br style="word-wrap: break-word; line-height: normal; ">5. 鍒悕鏇挎崲
6. 杈撳叆鍜岃緭鍑虹殑閲嶅畾鍚戯紙濡?>  < 鍜?|錛?br style="word-wrap: break-word; line-height: normal; ">7. 鍙橀噺鏇挎崲
8. 鍛戒護鏇挎崲
9. 鏂囦歡鍚嶆墿灞?br style="word-wrap: break-word; line-height: normal; ">錛圔ourne shell 鐨勮В閲婇『搴忔湰璐ㄤ笂鏄竴鏍風殑錛岄櫎浜嗗畠涓嶆墽琛屽巻鍙叉浛鎹㈠拰鍒悕鏇挎崲涔嬪錛?br style="word-wrap: break-word; line-height: normal; ">
鎵浠?br style="word-wrap: break-word; line-height: normal; ">A=B  echo    $A

鐨勬墽琛岃繃紼嬪簲璇ユ槸榪欐牱鐨勶細
1. 娌℃湁鍘嗗彶鎿嶄綔絎︼紝 鍥犳涓嶈繘琛屽巻鍙叉浛鎹紙Bourne shell 涓嶆墽琛岃繖涓姝ワ級
2. 鍒嗚璇嶏紝姣忕鍒版湭鍔犲紩鍙風殑絀虹櫧瀛楃灝變細浜х敓涓涓柊“璇?#8221;銆傝繖浜涜瘝鏄?A=B銆乪cho銆?A銆?br style="word-wrap: break-word; line-height: normal; ">3. shell 灝嗗懡浠よ鏀懼埌鍘嗗彶鍒楄〃涓傦紙Bourne shell 涓嶆墽琛岃繖涓姝ワ級
4. 娌℃湁寮曞彿闇瑕佽В閲?br style="word-wrap: break-word; line-height: normal; ">5. 娌℃湁鍒悕闇瑕佹浛鎹?br style="word-wrap: break-word; line-height: normal; ">6. 娌℃湁杈撳叆鎴栬緭鍑洪噸瀹氬悜闇瑕佸鐞?br style="word-wrap: break-word; line-height: normal; ">7. shell娉ㄦ剰鍒板彉閲?A錛屽茍鎶婂畠鏇挎崲鎴愮┖
8. shell瀵繪壘宸﹀崟寮曞彿錛屾墽琛屽乏鍗曞紩鍙蜂腑鐨勪換浣曞懡浠わ紝騫朵笖灝嗗懡浠ょ殑杈撳嚭鎻掑叆鍒板懡浠よ涓傚湪鏈緥涓紝娌℃湁榪欐柟闈㈢殑浜嬮渶瑕佸仛銆傦紙濡傛灉宸﹀崟寮曞彿鍐呮湁閫氶厤絎︽垨鑰呭彉閲忥紝閭d箞鍦╯hell榪愯宸﹀崟寮曞彿涓殑鍛戒護涔嬪墠瀹冧滑鏄笉浼氳瑙i噴鐨勶級
9. shell瀵繪壘閫氶厤絎︺傛湰渚嬩腑娌℃湁錛屼笉闇瑕佸鐞?br style="word-wrap: break-word; line-height: normal; ">10. shell 鎵ц A=B錛?鎵ц echo 銆?/span>



]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              欧美激情一区二区三级高清视频| 亚洲精品五月天| 欧美淫片网站| 亚洲一区二区三区久久| 一区二区三区四区精品| 日韩视频专区| 夜夜嗨av一区二区三区网站四季av| 亚洲国产日韩一区二区| 久久伊人一区二区| 免费国产自线拍一欧美视频| 欧美好骚综合网| 一本色道精品久久一区二区三区| 亚洲肉体裸体xxxx137| 免费观看成人www动漫视频| 欧美激情一区二区久久久| 蜜臀a∨国产成人精品| 亚洲福利一区| 国产精品99久久99久久久二8| 亚洲素人在线| 午夜视频一区| 麻豆精品传媒视频| 欧美精品一级| 国产乱子伦一区二区三区国色天香| 国产精品swag| 一区二区三区无毛| 一本久道久久综合狠狠爱| 午夜国产精品视频| 免费成人黄色片| 99国产一区| 久久米奇亚洲| 欧美丝袜第一区| 国产在线播放一区二区三区| 日韩一区二区高清| 麻豆精品网站| 国产精品久久久久高潮| 在线观看国产精品网站| 一区二区精品在线观看| 久久久久久免费| 日韩天天综合| 久久永久免费| 国产欧美日韩不卡免费| 亚洲美女视频网| 久久夜色精品国产噜噜av| 亚洲精品免费看| 美女爽到呻吟久久久久| 国产情侣一区| 一区二区三区日韩欧美| 亚洲精美视频| 蜜臀99久久精品久久久久久软件| 亚洲欧美国产另类| 欧美三区在线观看| 亚洲精品资源| 亚洲裸体视频| 免费观看日韩av| 久久精品人人做人人爽| 国产精品日韩欧美综合| 一级成人国产| 亚洲人成网站777色婷婷| 久久免费国产| 狠色狠色综合久久| 久久免费高清| 欧美中在线观看| 国产婷婷色综合av蜜臀av| 亚洲影音先锋| 亚洲天堂网站在线观看视频| 欧美日韩黄色大片| 一本色道久久综合精品竹菊| 欧美黄色小视频| 久久亚洲不卡| 亚洲第一网站| 国产欧美日韩专区发布| 久久综合九色综合欧美就去吻 | 亚洲激情av在线| 亚洲免费一在线| 亚洲丝袜av一区| 国产精品免费网站在线观看| 亚洲午夜羞羞片| 亚洲一区二区三区激情| 国产精品日本精品| 一本色道久久综合精品竹菊| 99综合视频| 先锋亚洲精品| 韩国成人理伦片免费播放| 久久男人av资源网站| 久久精品亚洲| 最新亚洲一区| 日韩视频在线免费| 久久精品国产清高在天天线| 午夜精品理论片| 狠狠色伊人亚洲综合成人| 国产精品日韩欧美大师| 久久免费视频在线观看| 欧美成人一区二区三区在线观看| 一本不卡影院| 久久av资源网| 亚洲精选大片| 亚洲欧美视频一区| 樱桃国产成人精品视频| 亚洲黄色性网站| 国产精品日本一区二区| 久久综合色8888| 欧美日本免费| 久久欧美肥婆一二区| 欧美黄色一区| 久久国产加勒比精品无码| 欧美在线免费观看亚洲| 欧美ab在线视频| 欧美在线亚洲一区| 欧美国产日韩视频| 欧美在线免费视屏| 欧美专区在线播放| 美女啪啪无遮挡免费久久网站| 一区二区三区欧美视频| 久久国产一区二区三区| 亚洲私人影院在线观看| 久久免费视频观看| 欧美怡红院视频| 欧美精品自拍| 欧美福利电影在线观看| 国产区精品在线观看| 亚洲精品日韩在线| 有坂深雪在线一区| 亚洲欧美日韩区| 99视频精品全部免费在线| 久久久久se| 欧美亚洲免费高清在线观看| 欧美激情aaaa| 欧美成人精品福利| 国产视频欧美视频| 亚洲尤物视频网| 亚洲欧洲一二三| 久久亚洲影音av资源网| 欧美午夜不卡在线观看免费| 欧美jizzhd精品欧美巨大免费| 国产精品日日摸夜夜添夜夜av | 亚洲一区二区三区中文字幕在线 | 欧美高清在线视频| 美女性感视频久久久| 国产日韩欧美精品| 亚洲免费一级电影| 国产精品午夜电影| 亚洲无人区一区| 一区二区日韩伦理片| 欧美激情第二页| 亚洲欧洲精品一区二区| 亚洲乱码一区二区| 欧美日韩精品免费观看视一区二区 | 久久xxxx精品视频| 国产精品国产三级国产aⅴ浪潮| 亚洲美女黄网| 亚洲无亚洲人成网站77777| 亚洲国产精品福利| 亚洲破处大片| 亚洲毛片播放| 欧美日韩精品免费观看视一区二区| 亚洲精品美女久久7777777| 亚洲图片欧美日产| 国产日韩欧美在线视频观看| 亚洲欧美另类在线观看| 久久激情综合| 亚洲国产精品久久久| 欧美国产日本在线| 亚洲一本大道在线| 国产精品一级久久久| 欧美在线日韩| 亚洲国产一区在线| 亚洲午夜激情在线| 久久精品在线视频| 亚洲国产综合91精品麻豆| 亚洲毛片播放| 亚洲二区视频| 亚洲综合大片69999| 国产主播喷水一区二区| 另类亚洲自拍| 亚洲素人一区二区| 美日韩丰满少妇在线观看| 久久久久久穴| 99热免费精品在线观看| 久久久福利视频| 99精品国产在热久久| 亚洲欧美自拍偷拍| 欧美成人久久| 亚洲一区免费在线观看| 国产一区视频观看| 欧美日韩国内| 久久午夜国产精品| 亚洲一区二区av电影| 欧美成人a视频| 欧美一区二区三区婷婷月色 | 国产日韩一区二区三区| 久久午夜电影网| 亚洲网站视频福利| 亚洲黄色成人网| 亚洲人精品午夜| 国产精品一区一区三区| 欧美高清视频一二三区| 欧美一区二区三区四区在线观看| 亚洲欧洲在线一区| 久久久亚洲精品一区二区三区| 最新亚洲激情|