判斷文字檔是否出現 "i=0" 字串 - Linux

Isabella avatar
By Isabella
at 2011-08-17T21:58

Table of Contents

※ 引述《mself (mself)》之銘言:
: dear 各位
:
: 我想寫 bash shell 判斷文字檔是否包含 "i=0" 這個字串
: 我用 result=`grep "i=0" text.txt`
: 再判斷 if [$result==""]
:
: 因為$result裡包含 "="
: 我這樣寫會有問題
:
: 請問怎麼做比較對呢?
: 謝謝
:
: --
Tags: Linux

All Comments

Oliver avatar
By Oliver
at 2011-08-21T06:50
if [ "$result" != "" ]; then ....
if ["$result"!=""];then .... not this
Isla avatar
By Isla
at 2011-08-21T17:14
mind the "space" before ']' and after '['
Kristin avatar
By Kristin
at 2011-08-24T02:19
input " i = 0 someword " in ur text file,
Hazel avatar
By Hazel
at 2011-08-25T18:00
then echo $result :)
Kristin avatar
By Kristin
at 2011-08-27T12:35
謝謝~確實是中刮號前後空白的關係~
Andrew avatar
By Andrew
at 2011-08-28T03:36
[是個執行檔 和test差不多 不過[的最後面一定要接著]
Ophelia avatar
By Ophelia
at 2011-08-29T16:31
所以要用空白隔開 要不然他會認為你要執行["$result"!=""]
Franklin avatar
By Franklin
at 2011-08-31T05:00
謝謝 ckclark 講解其中的原理~

刪除包含某字串的整行

Delia avatar
By Delia
at 2011-08-17T13:27
※ 引述《bendog.bbsatbbs.cs.nctu.edu.tw (bendog)》之銘言: : 應該可以用置換吧。 : sed -e and#39;s/指定字串//and#39;; : ※ 引述《Leeng.bbsatptt.cc (老千)》之銘言: : andgt; 如果某行包含 apple : a ...

Dovecot x sendmail

Yedda avatar
By Yedda
at 2011-08-17T12:17
各位好: 我架設好一台mail server了!! (只可以內部連線) 使用sendmail 與 dovecot (目前沒有DNS的問題,寄信都是先用ip來直接寄信) 以同樣的方式去架設另外一台 所有的連線都成功 但卻發現新架設的那一台有一個很奇怪的現象 Q:利用郵件軟體收信 ...

當機原因 怎麼查?

Rebecca avatar
By Rebecca
at 2011-08-17T08:47
我裝了一部CentOS 前天當機一次 螢幕全部黑掉 鍵鼠都不能動 復機之後一樣運作 請問一下 我可以去哪邊找當時可能的當機情況嗎?? - ...

用VM安裝完UBUNTU變醜???

Charlotte avatar
By Charlotte
at 2011-08-17T02:27
※ 引述《ckvir (ckvir)》之銘言: : 我用VirutalBox安裝ubuntu : 之前安裝完都好好的 : 不過最近把他移除在安裝一次 : 發現安裝完 桌面上排選單列變很醜 都灰灰一塊一塊的 : 之前開終端機背景是黑的 : 現在開背景變白的 : 這是什麼關係? : 我全部設定都沒動過 ...

判斷文字檔是否出現 "i=0" 字串

Puput avatar
By Puput
at 2011-08-16T23:26
dear 各位 我想寫 bash shell 判斷文字檔是否包含 and#34;i=0and#34; 這個字串 我用 result=`grep and#34;i=0and#34; text.txt` 再判斷 if [$result==and#34;and#34;] 因為$result裡包含 and#34; ...