<?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>Jean - 记录成长历程 &#187; bash</title>
	<atom:link href="http://www.zhangyiqun.net/tag/bash/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zhangyiqun.net</link>
	<description>让世界更美好一点儿</description>
	<lastBuildDate>Wed, 07 Dec 2011 14:04:37 +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>bash中的$</title>
		<link>http://www.zhangyiqun.net/164.html</link>
		<comments>http://www.zhangyiqun.net/164.html#comments</comments>
		<pubDate>Fri, 27 Mar 2009 12:13:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[脚本编程]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[shell编程]]></category>

		<guid isPermaLink="false">http://www.zhangyiqun.cn/?p=164</guid>
		<description><![CDATA[$0  脚本名  $#  位置参量个数  $*  所有的位置参量  $@  未加双引号时，与$*的含义相同  &#8220;$*&#8221;  单个变量(例如：&#8221;$1 $2 $3&#8243;)  &#8220;$@&#8221;  多个单独的变量(例如：&#8221;$1&#8243; &#8220;$2&#8243; &#8220;$3&#8243;)  $1 … ${10}  单独的位置参量<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角1</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角2</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell中的判断</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F155.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell编程的基本框架</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  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>$0  脚本名 </p>
<p>$#  位置参量个数 </p>
<p>$*  所有的位置参量 </p>
<p>$@  未加双引号时，与$*的含义相同 </p>
<p>&#8220;$*&#8221;  单个变量(例如：&#8221;$1 $2 $3&#8243;) </p>
<p>&#8220;$@&#8221;  多个单独的变量(例如：&#8221;$1&#8243; &#8220;$2&#8243; &#8220;$3&#8243;) </p>
<p>$1 … ${10}  单独的位置参量</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角1</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角2</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell中的判断</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F155.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell编程的基本框架</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  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://www.zhangyiqun.net/164.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shell中的判断</title>
		<link>http://www.zhangyiqun.net/167.html</link>
		<comments>http://www.zhangyiqun.net/167.html#comments</comments>
		<pubDate>Tue, 24 Mar 2009 10:22:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[脚本编程]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.zhangyiqun.cn/?p=167</guid>
		<description><![CDATA[2009-08-01 更名为shell中的判断，根据生产环境的脚本编程经验增加一些内容。 使用if判断进程是否存在，只是学个套路，实际上有简单的语句。 ?View Code SHELL#!/bin/bash remote=`ps aux &#124; awk '$11 ~ /htt/{print $11}'&#124;sed -n 2p` if [ &#34;X${remote}&#34; != &#34;X&#34; ] then echo &#34;ok&#34; else echo &#34;not ok&#34; fi 在判断中使用正则 ?View Code SHELL #!/bin/bash # Scriptname: xcolors &#160; 1 echo -n &#34;Choose a foreground color for your xterm window: &#34; read color 2 case [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角2</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F1081.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell技巧分享</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角1</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F333.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell面试题一个，对比小数大小</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  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><strong>2009-08-01 更名为shell中的判断，根据生产环境的脚本编程经验增加一些内容。</strong></p>
<p>使用if判断进程是否存在，只是学个套路，实际上有简单的语句。</p>
<p><span id="more-167"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p167code4'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1674"><td class="code" id="p167code4"><pre class="shell" style="font-family:monospace;">#!/bin/bash
remote=`ps aux | awk '$11 ~ /htt/{print $11}'|sed -n 2p`
if [ &quot;X${remote}&quot; != &quot;X&quot; ]
then
        echo &quot;ok&quot;
else
        echo &quot;not ok&quot;
fi</pre></td></tr></table></div>

<p>在判断中使用正则</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p167code5'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1675"><td class="code" id="p167code5"><pre class="shell" style="font-family:monospace;">    #!/bin/bash
    # Scriptname: xcolors 
&nbsp;
1   echo -n &quot;Choose a foreground color for your xterm window: &quot;
    read color
2   case &quot;$color&quot; in
3   [Bb]l??)
4        xterm -fg blue -fn terminal &amp;amp;
5        ;;
6   [Gg]ree*)
        xterm -fg darkgreen -fn terminal &amp;amp;
        ;;
7   red | orange)              # The vertical bar means &quot;or&quot;
        xterm -fg &quot;$color&quot;  -fn terminal &amp;amp;
        ;;
8   *)
        xterm -fn terminal
        ;;
9   esac
10  echo  &quot;Out of case command&quot;</pre></td></tr></table></div>

<p>使用圆括号做运算判断</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p167code6'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1676"><td class="code" id="p167code6"><pre class="shell" style="font-family:monospace;">1   $ x=2
    $ y=3 
&nbsp;
2   (( x &amp;gt; 2 ))
    echo $?
    1 
&nbsp;
3   (( x &amp;lt; 2 ))
    echo $?
    0 
&nbsp;
4   (( x == 2 &amp;amp;&amp;amp; y == 3 ))
    echo $?
    0 
&nbsp;
5   (( x &amp;gt; 2 || y &amp;lt; 3 ))
    echo $?
    1</pre></td></tr></table></div>

<p><strong>2009-03-24 这篇日志名为shell中的test，主要记录了使用test探测文件的方法。</strong></p>
<p>测试操作符  测试结果为真时需满足的条件</p>
<p>–b filename  块专用文件</p>
<p>–c filename  字符专用文件</p>
<p>–d filename  目录存在</p>
<p>–e filename  文件存在</p>
<p>–f filename  普通文件存在且不是目录</p>
<p>–G filename  文件存在且属于有效组ID时为真</p>
<p>–g filename  Set–group–ID被设置</p>
<p>–k filename  Sticky位被设置</p>
<p>–L filename  文件是一个符号链接</p>
<p>–p filename  文件是一个命名管道</p>
<p>–O filename  文件存在且属于有效用户ID</p>
<p>–r filename  文件可读</p>
<p>–S filename  文件是一个socket</p>
<p>–s filename  文件大小非0</p>
<p>–t fd  如果fd(文件描述符)被一个终端打开则为真</p>
<p>–u filename  Set–user–ID位被设置</p>
<p>–w filename  文件可写</p>
<p>–x filename  文件可执行</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角2</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F1081.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell技巧分享</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角1</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F333.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell面试题一个，对比小数大小</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  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://www.zhangyiqun.net/167.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bash的边边角角2</title>
		<link>http://www.zhangyiqun.net/106.html</link>
		<comments>http://www.zhangyiqun.net/106.html#comments</comments>
		<pubDate>Fri, 20 Mar 2009 14:14:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[脚本编程]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.zhangyiqun.cn/?p=106</guid>
		<description><![CDATA[read -r 允许输入包含反斜杠 ^^ &#8211; 撤销上次操作 ls -L ^L^l 命令行中使用注释 ls # l ls中使用正则 ls [!0-9] 运算 echo $[500+1000] 防止变量污染 abc=123 echo ${abc}456 touch {1,2} 等同于touch 1a,2a 建立带空格的文件touch &#8220;i&#8217;m good boy&#8221; [ * ]中括号中头尾有空格表内建命令 :永远返回0，用while写死循环时候用 .是sourse的缩写，在当前shell下执行某脚本 su != su &#8211; 前者是于当前shell环境下打开一个子shell（所以环境变量未变），后者则是开启一个全新的shell环境。 rpm -ivh &#8211;nodeps 忽略依存关系装包 declare –i 定义整型变量.(如果给整型变量赋一个字符串值，则bash将把变量赋值为0) sudo 可以让你切换身份来进行某项任务，例如我们的 root 使用 sshd 的权限去进行某项任务！ 要注意，因为我们无法使用『 su [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash中的$</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角1</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell中的判断</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F115.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell面试题</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  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>read -r 允许输入包含反斜杠</p>
<p>^^ &#8211; 撤销上次操作</p>
<p>ls -L<br />
^L^l</p>
<p>命令行中使用注释</p>
<p>ls # l</p>
<p>ls中使用正则</p>
<p>ls [!0-9]<br />
<span id="more-106"></span><br />
运算</p>
<p>echo $[500+1000]</p>
<p>防止变量污染</p>
<p>abc=123<br />
echo ${abc}456</p>
<p>touch {1,2} 等同于touch 1a,2a</p>
<p>建立带空格的文件touch &#8220;i&#8217;m good boy&#8221;</p>
<p>[ * ]中括号中头尾有空格表内建命令</p>
<p>:永远返回0，用while写死循环时候用</p>
<p>.是sourse的缩写，在当前shell下执行某脚本</p>
<p>su != su &#8211; 前者是于当前shell环境下打开一个子shell（所以环境变量未变），后者则是开启一个全新的shell环境。</p>
<p>rpm -ivh &#8211;nodeps 忽略依存关系装包</p>
<p>declare –i 定义整型变量.(如果给整型变量赋一个字符串值，则bash将把变量赋值为0)</p>
<p>sudo 可以让你切换身份来进行某项任务，例如我们的 root 使用 sshd 的权限去进行某项任务！ 要注意，因为我们无法使用『 su &#8211; sshd 』去切换系统帐号 (因为系统帐号的 shell 是 /sbin/nologin)， 这个时候 sudo 真是他 X 的好用了！</p>
<p>bash只支持整型运算，但可以使用bc，awk和nawk工具来处理更复杂的运算</p>
<p>备份MBR</p>
<p>dd if=/dev/sda of=/mbr.bak bs=512 count=1</p>
<p>清空MBR<br />
dd if=/dev/zero of=/dev/sda bs=446 count=1</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash中的$</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角1</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell中的判断</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F115.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell面试题</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  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://www.zhangyiqun.net/106.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bash的边边角角1</title>
		<link>http://www.zhangyiqun.net/86.html</link>
		<comments>http://www.zhangyiqun.net/86.html#comments</comments>
		<pubDate>Fri, 13 Mar 2009 14:36:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[脚本编程]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell编程]]></category>

		<guid isPermaLink="false">http://www.zhangyiqun.cn/?p=86</guid>
		<description><![CDATA[1、除特别说明外，本博客内容皆为原创，可以自由转载传播，但请署名及注明出处，不尊重别人劳动成果的不欢迎； 2、本博客内容遵守“署名-非商业性使用-禁止演绎 2.5 中国大陆”协议； 前言 当你手里只有一把锤子时，所有遇到的问题都会被看成是钉子。 1.写一个脚本报告用户信息，这个脚本只能添加一个参数，此参数为用户名，脚本可以报告系统中是否有此用户。如果有，程序报告：user exist .不在报告 no this user： 我认为很好的写法 #!/bin/bash if [ $# -ne 1 ] then      echo ERROR exit 1 fi grep ^$1: passwd &#38;&#62; /dev/null if [ $? -eq 0 ] then      echo User exist else      echo No this user fi 我的写法 #!/bin/bash [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash中的$</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角2</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell中的判断</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F155.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell编程的基本框架</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  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 class="MsoNormal"><span>1、除特别说明外，本博客内容皆为原创，可以自由转载传播，但请署名及注明出处，不尊重别人劳动成果的不欢迎；</span></p>
<p><span>2、本博客内容遵守“</span><a href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/" target="_blank"><span>署名-非商业性使用-禁止演绎 2.5 中国大陆</span></a><span>”协议；</span></p>
<p>前言<br />
<strong>当你手里只有一把锤子时，所有遇到的问题都会被看成是钉子。</strong></p>
<p><span id="more-86"></span><br />
<strong>1.写一个脚本报告用户信息，这个脚本只能添加一个参数，此参数为用户名，脚本可以报告系统中是否有此用户。如果有，程序报告：user exist    .不在报告 no this user：</strong></p>
<p>我认为很好的写法</p>
<blockquote><p>#!/bin/bash<br />
if [ $# -ne 1 ]<br />
then<br />
     echo ERROR<br />
exit 1<br />
fi<br />
grep ^$1: passwd &amp;&gt; /dev/null<br />
if [ $? -eq 0 ]<br />
then<br />
     echo User exist<br />
else<br />
     echo No this user<br />
fi</p></blockquote>
<p>我的写法</p>
<blockquote><p>#!/bin/bash<br />
grep $1 /etc/passwd &gt; /dev/null<br />
if (( $? == 0 ))<br />
then<br />
echo &#8220;YES&#8221;<br />
else<br />
echo &#8220;NO&#8221;<br />
fi</p></blockquote>
<p>不足：没有制造<strong>错误信号的exit 1</strong> ，细节。</p>
<p><strong>2.输出一个算术乘法表 （之前完全没写对）</strong></p>
<blockquote><p>#!/bin/bash</p>
<p>for ((i=1;i&lt;=9;i++))</p>
<p>do</p>
<p>        for ((z=1;<span style="color: #ff0000;">z&lt;=i</span>;z++))</p>
<p>        do</p>
<p>                echo -n ${z}x$i=$[$i*$z]<span style="color: #ff0000;">&#8216;  &#8217;</span></p>
<p>        done</p></blockquote>
<blockquote><p>        <span style="color: #ff0000;">echo</span></p>
<p><span style="color: #ff0000;"><span style="color: #000000;">done</span></span></p></blockquote>
<div>纯属娱乐题。</div>
<div><strong>3.提取出/usr/share/doc 目录下的所有的文件名为index.html的文件。把他们集中放在／tmp／index 目录中。文件名字按提取顺序更名标记index1、index2 ……</strong></div>
<blockquote><p>绝对的边边角角，主要是红色部分的使用<br />
#!/bin/bash</p>
<p>x=0</p>
<p>for i in <span style="color: #ff0000;">`</span>find /usr/share/doc -name index.html<span style="color: #ff0000;">`</span></p>
<p>do</p>
<p>        ((x++))</p>
<p>        cp ${i} /tmp/index/index.html.$x</p></blockquote>
<blockquote><p>done</p></blockquote>
<p><strong>4.统计出*.zhangyiqun.cn出现的次数，并进行排序。</strong></p>
<p>http://www.zhangyiqun.cn/index.html</p>
<p>http://www.zhangyiqun.cn/1.html</p>
<p>http://post.zhangyiqun.cn/index.html</p>
<p>http://mp3.zhangyiqun.cn/index.html</p>
<p>http://www.zhangyiqun.cn/3.html</p>
<p>http://post.zhangyiqun.cn/2.html</p>
<p>前阵子写过统计攻击者ip的脚本和这个类似，主要用到了sort 和uniq，这俩命令在统计中的作用实在太大了。</p>
<blockquote><p>awk &#8216;BEGIN{FS=&#8221;/&#8221;} {print $3}&#8217; zhangyiqun | sort | uniq -c | sort -r</p></blockquote>
<p>以下三道题来自 http://bbs.chinaunix.net/archiver/?tid-950419.html</p>
<p>write a shell script only to list the hidden items of a designated directory.the designated directory must be acquired as a command parameter.  if the parameter is not a  directory , print a warning message</p>
<p>主要是考察对ls是否熟悉。</p>
<blockquote><p>ls -A -l | awk &#8216;$NF ~ /^\./{print $NF}&#8217;</p></blockquote>
<p>write a shell script to remove all the empty . txt files in your current directory and print the number of removed files</p>
<blockquote><p>find /path -name &#8220;*.txt&#8221; -size 0</p></blockquote>
<p>there is a famous game which is &#8220;counting seven&#8221; . now we use shell script to implement the game . print the number from 1 to 1000 ,omitting the number which has 7 in it or is a multiple of 7</p>
<blockquote><p>#!/bin/bash</p>
<p>count=0</p>
<p>for((i=1;i&lt;=1000;i++))</p>
<p>do</p>
<p>if (( i%7 == 0 ))</p>
<p>then</p>
<p>((count++))</p>
<p>continue</p>
<p>fi</p>
<p>if echo $i | grep &#8217;7&#8242; <span style="color: #ff0000;">&amp;&gt;</span>/dev/null # &amp;&gt;的意思是把所有输出（&gt;和2&gt;）全部重定向</p>
<p>then</p>
<p>((count++))</p>
<p>continue</p>
<p>fi</p>
<p>echo $i</p>
<p>done</p>
<p>echo $count</p></blockquote>
<p>注：在shell中if就是判断命令的返回值&#8230; 0是正确，其他非0是错误</p>
<p style="margin:0;padding:0;height:1px;overflow:hidden;">
    <script type="text/javascript"><!--
        var wumiiSitePrefix = "http://www.zhangyiqun.net";
        var wumiiEnableCustomPos = false;
        var wumiiParams = "&#038;num=4&#038;mode=3&#038;displayInFeed=1&#038;version=1.0.5.5&#038;pf=WordPress3.2.1";
    //--></script><script type="text/javascript" src="http://widget.wumii.com/ext/relatedItemsWidget.htm"></script><a href="http://www.wumii.com/widget/relatedItems.htm" style="border:0;"><img src="http://static.wumii.com/images/pixel.png" alt="无觅相关文章插件，快速提升流量" style="border:0;padding:0;margin:0;" /></a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F164.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash中的$</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F106.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">bash的边边角角2</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F167.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell中的判断</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.zhangyiqun.net%2F155.html&from=http%3A%2F%2Fwww.zhangyiqun.net%2F86.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">shell编程的基本框架</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  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://www.zhangyiqun.net/86.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: www.zhangyiqun.net @ 2012-02-07 22:36:19 -->
