<?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>走出Windows &#187; 编程</title>
	<atom:link href="http://www.killwin.com/articles/tag/%e7%bc%96%e7%a8%8b/feed" rel="self" type="application/rss+xml" />
	<link>http://www.killwin.com</link>
	<description>抛弃Windows就是走向高效率</description>
	<lastBuildDate>Fri, 23 Sep 2011 12:50: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>Linux Shell 中进行条件判断</title>
		<link>http://www.killwin.com/articles/276.html</link>
		<comments>http://www.killwin.com/articles/276.html#comments</comments>
		<pubDate>Tue, 11 May 2010 07:41:21 +0000</pubDate>
		<dc:creator>LuckyBoy</dc:creator>
				<category><![CDATA[使用]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[编程]]></category>

		<guid isPermaLink="false">http://www.killwin.com/?p=276</guid>
		<description><![CDATA[一般用法是 if [ 条件 ]; then 执行语句 fi 要注意的是，条件要包含在方括号内，且条件和方括号相连的地方要有空格隔开，不然会出错 下面是转自网上的各种条件的写法 1、比较文件 -b file 若文件存在且是一个块特殊文件，则为真 -c file 若文件存在且是一个字符特殊文件，则为真 -d file 若文件存在且是一个目录，则为真 -e file 若文件存在，则为真 -f file 若文件存在且是一个规则文件，则为真 -g file 若文件存在且设置了SGID位的值，则为真 -h file 若文件存在且为一个符合链接，则为真 -k file 若文件存在且设置了"sticky"位的值 -p file 若文件存在且为一已命名管道，则为真 -r file 若文件存在且可读，则为真 -s file 若文件存在且其大小大于零，则为真 -u file 若文件存在且设置了SUID位，则为真 -w file 若文件存在且可写，则为真 -x file 若文件存在且可执行，则为真 -o file [...]]]></description>
			<content:encoded><![CDATA[<p>一般用法是 </p>
<blockquote><p>if [ 条件 ]; then<br />
    执行语句<br />
fi</p></blockquote>
<p>要注意的是，条件要包含在方括号内，且条件和方括号相连的地方要有空格隔开，不然会出错<br />
下面是转自网上的各种条件的写法</p>
<blockquote><p>1、比较文件<br />
-b file            若文件存在且是一个块特殊文件，则为真<br />
-c file            若文件存在且是一个字符特殊文件，则为真<br />
-d file            若文件存在且是一个目录，则为真<br />
-e file            若文件存在，则为真<br />
-f file            若文件存在且是一个规则文件，则为真<br />
-g file            若文件存在且设置了SGID位的值，则为真<br />
-h file            若文件存在且为一个符合链接，则为真<br />
-k file            若文件存在且设置了"sticky"位的值<br />
-p file            若文件存在且为一已命名管道，则为真<br />
-r file            若文件存在且可读，则为真<br />
-s file            若文件存在且其大小大于零，则为真<br />
-u file            若文件存在且设置了SUID位，则为真<br />
-w file            若文件存在且可写，则为真<br />
-x file            若文件存在且可执行，则为真<br />
-o file            若文件存在且被有效用户ID所拥有，则为真<br />
2、比较字符串<br />
-z string          若string长度为0，则为真<br />
-n string          若string长度不为0，则为真<br />
string1 = string2  若两个字符串相等，则为真<br />
string1 != string2 若两个字符串不相等，则为真<br />
3、比较整数<br />
int1 -eq int2      若int1等于int2，则为真<br />
int1 -ne int2      若int1不等于int2，则为真<br />
int1 -lt int2      若int1小于int2，则为真<br />
int1 -le int2      若int1小于等于int2，则为真<br />
int1 -gt int2      若int1大于int2，则为真<br />
int1 -ge int2      若int1大于等于int2，则为真</p>
<p>!expr              若expr为假则复合表达式为真。expr可以是任何有效的测试表达式<br />
expr1 -a expr2     若expr1和expr2都为真则整式为真<br />
expr1 -o expr2     若expr1和expr2有一个为真则整式为真<br />
注意：作为一个通用的规则，你应该在所有的$变量加上双引号来避免shell发生不正确的变量的替代。例如[ "$XX" -eq 3]中，如果XX为空而没有”“的就变成了[ -eq 3]这样会导致test命令语法错误。加上双引号之后就是["" -eq 3]，这样保证test命令成功运行而得到正确的结果。</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.killwin.com/articles/276.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

