条件。変数がBashスクリプトで処理されていない場合[閉じる]

条件。変数がBashスクリプトで処理されていない場合[閉じる]

単純なbashスクリプトがあります

#!/bin/bash
Result =$(zgrep -i "blocked session" /BACKUP/server.log.2019-06-23-06.gz | wc -l)

if [[ "$Result" -ge 1 ]];
 then
   echo "CRITICAL : The error string is found $Result times in server.log  file"
   exit 2
else
   echo "OK: No instances of the error string in the server.log file "
   exit 0
fi

wc -lは約1744個のエラー文字列インスタンスを正しくキャプチャしますが、if条件では使用されず、無効な終了コードを取得します。

++ zgrep -i "blocked session" /BACKUP/server.log.2019-06-23-06.gz
++ wc -l
+ Result =1744
/tmp/test.sh: line 4: Result: command not found
+ [[ '' -ge 1 ]]
+ echo OK: No instances of the error string in the server.log file '
OK: echo "OK: No instances of the error string in the server.log file 
+ exit 0

ここで何を見逃しているのか教えてください。

ベストアンサー1

2行目のスペースを削除します。

Result=$(zgrep -i "blocked session" /BACKUP/server.log.2019-06-23-06.gz | wc -l)

変える

Result =$(zgrep -i "blocked session" /BACKUP/server.log.2019-06-23-06.gz | wc -l)

おすすめ記事