<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[awk中如何输出单引号]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Tue, 22 Dec 2009 12:11:19 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	<textarea name="code" class="php" rows="15" cols="100">
mysql -e &quot;show processlist&quot;&#124;awk &#039;&#123;if($5 ==&nbsp;&nbsp;&quot;&#039;&#92;&#039;&#039;Sleep&#039;&#92;&#039;&#039;&quot;) print $1;print &quot;&#039;&#92;&#039;&#039;Sleep&#039;&#92;&#039;&#039;&quot; &#125;&#039;
&#039;Sleep&#039;
&#039;Sleep&#039;
&#039;Sleep&#039;
&#039;Sleep&#039;
&#039;Sleep&#039;
</textarea><br/><br/>最近在用awk拼写一段sql语句时，遇到了 单引号不能输出的 问题 。<br/>实在让人很困惑 ！<br/>awk中如何输出单引号 如何在awk中打印输出单引号呢 shell如何处理单引号呢 ？<br/>也就是shell中对单引号的处理问题<br/><br/>解决办法<br/>awk &#039;&#123;print &quot; &#039;&#92;&#039;&#039; &quot;&#125;&#039;<br/>把转义的单引号&#039;，用两个单引号括起来，使其不执行<br/><br/>原因是 ：括在双引号中的三种特殊字符不被忽略：$,&#92;,` ,即双引号会解释字符串的特别意思,而单引号直接使用字符串输出.<br/><br/>那么shell如何处理特殊字符的呢<br/>1. 单引号 ( &#039; &#039; )<br/>如果我们想查找的是Susan Goldberg，不能直接使用grep Susan Goldberg phonebook命令，grep会把Goldberg和phonebook当作需要搜索的文件<br/>howard@0[script]$ grep &#039;Susan Gold&#039; phonebook<br/>Susan Goldberg 403-212-4921<br/>当shell碰到第一个单引号时，它忽略掉其后直到右引号的所有特殊字符<br/>2. 双引号 ( &quot; &quot; )<br/>双引号作用与单引号类似，区别在于它没有那么严格。单引号告诉shell忽略所有特殊字符，而双引号只要求忽略大多数，具体说，括在双引号中的三种特殊字符不被忽略：$,&#92;,` ,即双引号会解释字符串的特别意思,而单引号直接使用字符串.如果使用双引号将字符串赋给变量并反馈它，实际上与直接反馈变量并无差别。如果要查询包含空格的字符串，经常会用到双引号。<br/>howard@0[script]$ x=*<br/>howard@0[script]$ echo $x<br/>hello.sh menus.sh misc.sh phonebook tshift.sh<br/>howard@0[script]$ echo &#039;$x&#039;<br/>$x<br/>howard@0[script]$ echo &quot;$x&quot;<br/>*<br/>这个例子可以看出无引号、单引号和双引号之间的区别。在最后一种情况中，双引号告诉shell在引号内照样进行变量名替换，所以shell把$x替换为＊，因为双引号中不做文件名替换，所以就把＊作为要显示的值传递给echo。<br/>对于第一种情况需要进一步说明，shell在给变量赋值时不进行文件名替换（这从第三种情况中也能看出来），各步骤发生的精确次序如下：<br/>shell扫描命令行，把x的值设为星号＊；<br/>shell再次扫描命令行，碰到星号＊，把它替换成当前目录下的文件清单；<br/>shell启动执行echo命令，把文件清单作为参数传递给echo.<br/>这个赋值的先后次序非常重要：shell先作变量替换，然后作文件名替换，最后把这行处理为参数<br/><br/>双引号直接斜杠转义：<br/><br/><div class="code">cat C.txt &#124;awk &#039;&#123;print &quot;grep -r &#039;&#92;&#039;&#039;^&quot; $1 &quot; &#039;&#92;&#039;&#039;&nbsp;&nbsp;./36107_game_20100910.txt&quot;&#125;&#039;&#124;awk&nbsp;&nbsp;&#039;&#123;print $0 &quot;&#124;awk&nbsp;&nbsp;&#039;&#92;&#039;&#039;&#123;print awk $1 &#92;&quot;&quot; &quot; &#92;&quot; $2&#125;&#039;&#92;&#039;&#039;&quot;&#125;&#039;</div><br/><br/><br/><div class="code">cat C.txt &#124;awk &#039;&#123;print &quot;grep -r &#039;&#92;&#039;&#039;^&quot; $1 &quot; &#039;&#92;&#039;&#039;&nbsp;&nbsp;./36107_game_20100910.txt&quot;&#125;&#039;&#124;awk&nbsp;&nbsp;&#039;&#123;print $0 &quot;&#124;awk&nbsp;&nbsp;&#039;&#92;&#039;&#039;&#123;print awk $1 &#92;&quot;&quot; &quot; &#92;&quot; $2&#125;&#039;&#92;&#039;&#039; &gt;&gt;&nbsp;&nbsp;DDD.txt&quot;&#125;&#039; &gt; CCC.txt</div><br/>3. 反引号(``)<br/>命令替换是指shell能够将一个命令的标准输出插在一个命令行中任何位置。shell中有两种方法作命令替换：把shell命令用反引号或者$(...)结构括起来，其中，$(...)格式受到POSIX标准支持，也利于嵌套。<br/>howard@0[script]$ echo The date and time is `date`<br/>The date and time is 三 6月 15 06:10:35 CST 2005<br/>howard@0[script]$ echo Your current working directory is $(pwd)<br/>Your current working directory is /home/howard/script.<br/>4. 反斜杠 backslash-escaped( &#92; )<br/>反斜杠一般用作转义字符,或称逃脱字符,linux如果echo要让转义字符发生作用,就要使用-e选项,且转义字符要使用双引号<br/>echo -e &quot;&#92;n&quot;<br/>反斜杠的另一种作用,就是当反斜杠用于一行的最后一个字符时，shell把行尾的反斜杠作为续行，这种结构在分几行输入长命令时经常使用。
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] awk中如何输出单引号]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>