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

Table of Contents

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

All Comments

Oliver avatarOliver2011-08-21
if [ "$result" != "" ]; then ....
if ["$result"!=""];then .... not this
Isla avatarIsla2011-08-21
mind the "space" before ']' and after '['
Kristin avatarKristin2011-08-24
input " i = 0 someword " in ur text file,
Hazel avatarHazel2011-08-25
then echo $result :)
Kristin avatarKristin2011-08-27
謝謝~確實是中刮號前後空白的關係~
Andrew avatarAndrew2011-08-28
[是個執行檔 和test差不多 不過[的最後面一定要接著]
Ophelia avatarOphelia2011-08-29
所以要用空白隔開 要不然他會認為你要執行["$result"!=""]
Franklin avatarFranklin2011-08-31
謝謝 ckclark 講解其中的原理~