<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>梁剑的Blog &#187; Shell</title>
	<atom:link href="http://icomes.net/category/%e6%8a%80%e6%9c%af%e7%ac%94%e8%ae%b0/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://icomes.net</link>
	<description>做有趣的事，做有用的人</description>
	<lastBuildDate>Sat, 05 Nov 2011 18:23:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>shell里${}的特殊功能</title>
		<link>http://icomes.net/2008/08/04/shell%e9%87%8c%e7%9a%84%e7%89%b9%e6%ae%8a%e5%8a%9f%e8%83%bd/</link>
		<comments>http://icomes.net/2008/08/04/shell%e9%87%8c%e7%9a%84%e7%89%b9%e6%ae%8a%e5%8a%9f%e8%83%bd/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 03:57:36 +0000</pubDate>
		<dc:creator>梁剑</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[技术笔记]]></category>

		<guid isPermaLink="false">http://tridot.cn/?p=152</guid>
		<description><![CDATA[假设我们定义了一个路径变量为： file=/dir1/dir2/dir3/my.file.txt 我们可以用 ${ } 分別替换获得不同的值： ${file#*/}：拿掉第一条 / 及其左边的字串：dir1/dir2/dir3/my.file.txt ${file##*/}：拿掉最后一条 / 及其左边的字串：my.file.txt ${file#*.}：拿掉第一个 . 及其左边的字串：file.txt ${file##*.}：拿掉最后一个 . 及其左边的字串：txt ${file%/*}：拿掉最后条 / 及其右边的字串：/dir1/dir2/dir3 ${file%%/*}：拿掉第一条 / 及其右边的字串：(空值) ${file%.*}：拿掉最后一个 . 及其右边的字串：/dir1/dir2/dir3/my.file ${file%%.*}：拿掉第一个 . 及其右边的字串：/dir1/dir2/dir3/my   简单来说就是 两个#（或者%）表示最大匹配 一个#（或者%）表示最小匹配 #从左边开始匹配，%从右边开始匹配 但是是找到匹配的被切掉．<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Ubunt9.04终于发布了" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Ficomes.net%2F2009%2F04%2F06%2Fubunt904%25E7%25BB%2588%25E4%25BA%258E%25E5%258F%2591%25E5%25B8%2583%25E4%25BA%2586%2F&from=http%3A%2F%2Ficomes.net%2F2008%2F08%2F04%2Fshell%25E9%2587%258C%25E7%259A%2584%25E7%2589%25B9%25E6%25AE%258A%25E5%258A%259F%25E8%2583%25BD%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15015339.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Ubunt9.04终于发布了</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="阅读空间的GM脚本" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Ficomes.net%2F2009%2F01%2F17%2F%25E9%2598%2585%25E8%25AF%25BB%25E7%25A9%25BA%25E9%2597%25B4%25E7%259A%2584gs%25E8%2584%259A%25E6%259C%25AC%2F&from=http%3A%2F%2Ficomes.net%2F2008%2F08%2F04%2Fshell%25E9%2587%258C%25E7%259A%2584%25E7%2589%25B9%25E6%25AE%258A%25E5%258A%259F%25E8%2583%25BD%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15015260.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">阅读空间的GM脚本</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="The Last Lecture" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Ficomes.net%2F2011%2F10%2F15%2Fthe-last-lecture%2F&from=http%3A%2F%2Ficomes.net%2F2008%2F08%2F04%2Fshell%25E9%2587%258C%25E7%259A%2584%25E7%2589%25B9%25E6%25AE%258A%25E5%258A%259F%25E8%2583%25BD%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/10/15/9228539.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">The Last Lecture</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="利用ssh tunnel建立本地sock代理" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Ficomes.net%2F2009%2F07%2F25%2F%25E5%2588%25A9%25E7%2594%25A8ssh-tunnel%25E5%25BB%25BA%25E7%25AB%258B%25E6%259C%25AC%25E5%259C%25B0sock%25E4%25BB%25A3%25E7%2590%2586%2F&from=http%3A%2F%2Ficomes.net%2F2008%2F08%2F04%2Fshell%25E9%2587%258C%25E7%259A%2584%25E7%2589%25B9%25E6%25AE%258A%25E5%258A%259F%25E8%2583%25BD%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15015597.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">利用ssh tunnel建立本地sock代理</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="ProgId" content="Word.Document" /><meta name="Generator" content="Microsoft Word 11" /><meta name="Originator" content="Microsoft Word 11" /></p>
<link href="file:///C:%5CDOCUME%7E1%5CIVERLE%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" /><!--[if gte mso 9]><xml>  <w:WordDocument>   <w:View>Normal</w:View>   <w:Zoom>0</w:Zoom>   <w:PunctuationKerning/>   <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>   <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>   <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>   <w:ValidateAgainstSchemas/>   <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>   <w:IgnoreMixedContent>false</w:IgnoreMixedContent>   <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>   <w:Compatibility>    <w:SpaceForUL/>    <w:BalanceSingleByteDoubleByteWidth/>    <w:DoNotLeaveBackslashAlone/>    <w:ULTrailSpace/>    <w:DoNotExpandShiftReturn/>    <w:AdjustLineHeightInTable/>    <w:BreakWrappedTables/>    <w:SnapToGridInCell/>    <w:WrapTextWithPunct/>    <w:UseAsianBreakRules/>    <w:DontGrowAutofit/>    <w:UseFELayout/>   </w:Compatibility>   <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>  </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml>  <w:LatentStyles DefLockedState="false" LatentStyleCount="156">  </w:LatentStyles> </xml><![endif]--><br />
<style> <!--  /* Font Definitions */  @font-face 	{font-family:宋体; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:SimSun; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;} @font-face 	{font-family:"\@宋体"; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0cm; 	margin-bottom:.0001pt; 	text-align:justify; 	text-justify:inter-ideograph; 	mso-pagination:none; 	font-size:10.5pt; 	mso-bidi-font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:宋体; 	mso-font-kerning:1.0pt;}  /* Page Definitions */  @page 	{mso-page-border-surround-header:no; 	mso-page-border-surround-footer:no;} @page Section1 	{size:612.0pt 792.0pt; 	margin:72.0pt 90.0pt 72.0pt 90.0pt; 	mso-header-margin:36.0pt; 	mso-footer-margin:36.0pt; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --> </style>
<p><!--[if gte mso 10]><br />
<style>  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:普通表格; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 	mso-para-margin:0cm; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} </style>
<p> <![endif]--></p>
<p class="MsoNormal" style="text-indent: 21pt"><span style="font-family: 宋体">假设我们定义了一个路径变量为：</span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US">file=/dir1/dir2/dir3/my.file.txt </span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span style="font-family: 宋体">我们可以用</span><span lang="EN-US"> ${ } </span><span style="font-family: 宋体">分別替换获得不同的值：</span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US">${file#*/}</span><span style="font-family: 宋体">：拿掉第一条</span><span lang="EN-US"> / </span><span style="font-family: 宋体">及其左边的字串：</span><span lang="EN-US">dir1/dir2/dir3/my.file.txt </span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US">${file##*/}</span><span style="font-family: 宋体">：拿掉最后一条</span><span lang="EN-US"> / </span><span style="font-family: 宋体">及其左边的字串：</span><span lang="EN-US">my.file.txt </span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US">${file#*.}</span><span style="font-family: 宋体">：拿掉第一个</span><span lang="EN-US"> . </span><span style="font-family: 宋体">及其左边的字串：</span><span lang="EN-US">file.txt </span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US">${file##*.}</span><span style="font-family: 宋体">：拿掉最后一个</span><span lang="EN-US"> . </span><span style="font-family: 宋体">及其左边的字串：</span><span lang="EN-US">txt </span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US">${file%/*}</span><span style="font-family: 宋体">：拿掉最后条</span><span lang="EN-US"> / </span><span style="font-family: 宋体">及其右边的字串：</span><span lang="EN-US">/dir1/dir2/dir3 </span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US">${file%%/*}</span><span style="font-family: 宋体" lang="ZH-TW">：拿掉第一条</span><span lang="EN-US"> / </span><span style="font-family: 宋体" lang="ZH-TW">及其右边的字串：</span><span lang="EN-US">(</span><span style="font-family: 宋体" lang="ZH-TW">空值</span><span lang="EN-US">) <o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US">${file%.*}</span><span style="font-family: 宋体">：拿掉最后一个</span><span lang="EN-US"> . </span><span style="font-family: 宋体">及其右边的字串：</span><span lang="EN-US">/dir1/dir2/dir3/my.file </span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US">${file%%.*}</span><span style="font-family: 宋体">：拿掉第一个</span><span lang="EN-US"> . </span><span style="font-family: 宋体">及其右边的字串：</span><span lang="EN-US">/dir1/dir2/dir3/my</span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span style="font-family: 宋体">简单来说就是</span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span style="font-family: 宋体">两个</span><span lang="EN-US">#</span><span style="font-family: 宋体">（或者</span><span lang="EN-US">%</span><span style="font-family: 宋体">）表示最大匹配</span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span style="font-family: 宋体">一个</span><span lang="EN-US">#</span><span style="font-family: 宋体">（或者</span><span lang="EN-US">%</span><span style="font-family: 宋体">）表示最小匹配</span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US">#</span><span style="font-family: 宋体">从左边开始匹配，</span><span lang="EN-US">%</span><span style="font-family: 宋体">从右边开始匹配</span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span style="font-family: 宋体">但是是找到匹配的被切掉．</span></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="用visio画的UML图例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Ficomes.net%2F2009%2F10%2F18%2F%25E7%2594%25A8visio%25E7%2594%25BB%25E7%259A%2584uml%25E5%259B%25BE%25E4%25BE%258B%2F&from=http%3A%2F%2Ficomes.net%2F2008%2F08%2F04%2Fshell%25E9%2587%258C%25E7%259A%2584%25E7%2589%25B9%25E6%25AE%258A%25E5%258A%259F%25E8%2583%25BD%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15015128.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">用visio画的UML图例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="The Last Lecture" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Ficomes.net%2F2011%2F10%2F15%2Fthe-last-lecture%2F&from=http%3A%2F%2Ficomes.net%2F2008%2F08%2F04%2Fshell%25E9%2587%258C%25E7%259A%2584%25E7%2589%25B9%25E6%25AE%258A%25E5%258A%259F%25E8%2583%25BD%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/10/15/9228539.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">The Last Lecture</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="利用ssh tunnel建立本地sock代理" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Ficomes.net%2F2009%2F07%2F25%2F%25E5%2588%25A9%25E7%2594%25A8ssh-tunnel%25E5%25BB%25BA%25E7%25AB%258B%25E6%259C%25AC%25E5%259C%25B0sock%25E4%25BB%25A3%25E7%2590%2586%2F&from=http%3A%2F%2Ficomes.net%2F2008%2F08%2F04%2Fshell%25E9%2587%258C%25E7%259A%2584%25E7%2589%25B9%25E6%25AE%258A%25E5%258A%259F%25E8%2583%25BD%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15015597.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">利用ssh tunnel建立本地sock代理</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="新主题iBlog2" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Ficomes.net%2F2009%2F09%2F15%2F%25E6%2596%25B0%25E4%25B8%25BB%25E9%25A2%2598iblog2%2F&from=http%3A%2F%2Ficomes.net%2F2008%2F08%2F04%2Fshell%25E9%2587%258C%25E7%259A%2584%25E7%2589%25B9%25E6%25AE%258A%25E5%258A%259F%25E8%2583%25BD%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/29/15014886.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">新主题iBlog2</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://icomes.net/2008/08/04/shell%e9%87%8c%e7%9a%84%e7%89%b9%e6%ae%8a%e5%8a%9f%e8%83%bd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

