<?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>丫忠的伺服器 &#187; shell script</title>
	<atom:link href="http://homeserver.com.tw/%E6%96%87%E7%AB%A0%E5%88%86%E9%A1%9E/shell-script/feed/" rel="self" type="application/rss+xml" />
	<link>http://homeserver.com.tw</link>
	<description>提供工作心得，教學文件的部落格</description>
	<lastBuildDate>Thu, 26 Aug 2010 03:38:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>shell script判斷參數</title>
		<link>http://homeserver.com.tw/shell-script/shell-script%e5%88%a4%e6%96%b7%e5%8f%83%e6%95%b8/</link>
		<comments>http://homeserver.com.tw/shell-script/shell-script%e5%88%a4%e6%96%b7%e5%8f%83%e6%95%b8/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 02:50:24 +0000</pubDate>
		<dc:creator>丫忠</dc:creator>
				<category><![CDATA[shell script]]></category>

		<guid isPermaLink="false">http://homeserver.com.tw/?p=626</guid>
		<description><![CDATA[最近丫忠在安裝伺服器的某些套件時，會遇到一些問題；例如：DNS(named)安裝完成後，接著要啟動named，但是就是啟動不了，於是就要開始從/etc/init.d/named這支shell script開始查起，看到shell script就有點頭痛了，因為shell script判斷的方式不像php，要判斷是否為檔案就用is_file，判斷是否為執行檔就用is_executable。
然而在shell script中判斷的方式都是用-f,-x &#8230;等方式，如果對於不常寫shell script的RD來講，還真的需要有一個可以參考的地方，於是丫忠把這些shell script判斷的參數貼上來，以便以後遇到時又要尋找，真麻煩!!



測試的標誌
代表意義


1. 關於某個檔名的『檔案類型』判斷，如 test -e filename 表示存在否


-e
該『檔名』是否存在？(常用)


-f
該『檔名』是否存在且為檔案(file)？(常用)


-d
該『檔名』是否存在且為目錄(directory)？(常用)


-b
該『檔名』是否存在且為一個 block device 裝置？


-c
該『檔名』是否存在且為一個 character device 裝置？


-S
該『檔名』是否存在且為一個 Socket 檔案？


-p
該『檔名』是否存在且為一個 FIFO (pipe) 檔案？


-L
該『檔名』是否存在且為一個連結檔？


2. 關於檔案的權限偵測，如 test -r filename 表示可讀否 (但 root 權限常有例外)


-r
偵測該檔名是否存在且具有『可讀』的權限？


-w
偵測該檔名是否存在且具有『可寫』的權限？


-x
偵測該檔名是否存在且具有『可執行』的權限？


-u
偵測該檔名是否存在且具有『SUID』的屬性？


-g
偵測該檔名是否存在且具有『SGID』的屬性？


-k
偵測該檔名是否存在且具有『Sticky bit』的屬性？


-s
偵測該檔名是否存在且為『非空白檔案』？


3. 兩個檔案之間的比較，如： test file1 -nt file2


-nt
(newer than)判斷 file1 是否比 file2 新


-ot
(older than)判斷 file1 是否比 file2 舊


-ef
判斷 file1 與 file2 是否為同一檔案，可用在判斷 hard link 的判定上。 [...]


本文相關的文章<ol><li><a href='http://homeserver.com.tw/%e7%b6%b2%e8%b7%af%e5%b7%a5%e5%85%b7/%e5%81%b5%e6%b8%ac%e7%b6%b2%e7%ab%99%e6%98%af%e5%90%a6%e6%9c%89%e6%94%af%e6%8f%b4%e7%b8%ae%e5%a3%93mod_deflatemod_gzipob_gzhandlerzlib/' rel='bookmark' title='Permanent Link: 偵測網站是否有支援壓縮(mod_deflate,mod_gzip,ob_gzhandler,zlib)'>偵測網站是否有支援壓縮(mod_deflate,mod_gzip,ob_gzhandler,zlib)</a></li>
<li><a href='http://homeserver.com.tw/php-example/wp-codebox-plugin-for-bash%e6%b8%ac%e8%a9%a6/' rel='bookmark' title='Permanent Link: WP-CODEBOX Plugin for bash測試'>WP-CODEBOX Plugin for bash測試</a></li>
<li><a href='http://homeserver.com.tw/apache/http%e5%a3%93%e5%8a%9b%e6%b8%ac%e8%a9%a6%e5%b7%a5%e5%85%b7/' rel='bookmark' title='Permanent Link: http壓力測試工具'>http壓力測試工具</a></li>
</ol>]]></description>
		<wfw:commentRss>http://homeserver.com.tw/shell-script/shell-script%e5%88%a4%e6%96%b7%e5%8f%83%e6%95%b8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
