要执行时请打.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
要执行时请打.ppt

test command - 1 Shell Script程式撰寫常用到測試參數的條件是否符合,test指令即用來做測試用. 請特別注意 test這個指令亦可以用中括號[] 取代之. 下面的test指令是針對檔案而測試 test –d file 測試file是否為目錄 test -f file 測試file是否為一般檔案 test -L file 測試file是否為連結檔 test –r file 測試file是否可讀 test -w file 測試file是否可寫 test -x file 測試file是否可執行 test –e file 測試file是否存在 test -s file 測試file是否檔案大小0 test -S file 測試file是否是一個Socket test command-2 下面的test指令最常用來做if及迴圈條件的判斷式. 下面的test指令是針對數值而測試 test n1 –eq n2 即測試 n1=n2 ? test n1 –ne n2 即測試 n1?n2 ? test n1 –ge n2 即測試 n1=n2 ? test n1 –gt n2 即測試 n1n2 ? test n1 –le n2 即測試 n1=n2 ? test n1 –lt n2 即測試 n1n2 ? test command-3 下面的test指令是對 expr的式子再做是否真(true)或假(false)的判斷 test !expr 測試expr的結果是否為假 test expr1 –a expr2 測試二個式子取AND的結果 test expr1 –o expr2 測試二個式子取OR的結果 Shell Script 練習 熟悉Unix的你,如果常常要去建立執行檔,那麼可不可以直接寫個script來完成? 要執行時請打: sh makex makex makex 檔名 Shell Script 練習 Shell Script 練習 Shell Script 練習 Shell Script 練習 下面的test指令是對字串(s)做比較 test str1 = str2 測試是否二個字串相等? test str1 == str2 測試是否二個字串相等? test str1 != str2 測試是否二個字串不等? test –n str 測試是否字串長度不為0? test –z str 測試是否為字串長度為0? # make executable file #!/bin/sh chmod u+x $1 echo $1 is now executable ls –l $1 # make wc more readable #!/bin/sh set `wc $1` echo “File: $4” echo “lines: $1” echo “words: $2” echo “characters: $3” 如果我們需要利用wc指令來看檔案內容的行數及字數,那可不可以寫個script讓列出的內容更明確?? 要執行時請打: makex morewc morewc 檔名 檔名: makex 檔名: morewc #A daily reminder service #!/bin/sh echo “===remind of the week==” Set `date` case $1 in 週一) echo “Plan the week”;; 週二) echo “meet teacher” ;; 週三) echo “Join the club” ;; 週四) echo “Write homework” ;; 週五) echo “Wash my cloth” ;; 週六) echo “go home” ;; 週日) echo “enjoy the NBA” ;; *) echo “哈..這是什麼日子啊?” esac 想寫一個script檔案來提醒您週一到週日每天應做的事. 要執行時請打: makex remember remember 檔名: remember 我們要將此檔案的檔名放入登入檔: .bash_profile 中 接著可以測試 source .login 或用 ./.profile #delete file interactively #!/bin/sh fname = $1 if test ! –f $fname then echo “There is no file \”$fname\”.” else echo

文档评论(0)

youbika + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档