Bashエラー:欠落[:`]'がありません

Bashエラー:欠落[:`]'がありません

ルートファイルシステムでLinuxファイルシステムのディスク使用量を確認し、システムが6%を超えると警告メッセージを表示する単純なスクリプトをBashに書きました。

コマンドが端末で実行されていますが、ステートメントを試行すると、if16行目でこのエラーが発生します。 [: missing] ''

  1 #!/bin/bash
  2 
  3
  4  
  5 clear
  6 #checking for usage on the system and saving in a file usage1
  7 df -h / >usage1
  8
  9 #display current use to the screen
 10 clear
 11 echo
 12 awk '$5>6' usage1
 13
 14 #Creating variable to use in the awk if statemant
 15 usage2= "awk '{print $5}'/home/peters/usage1 | tail -n1 |cut -c1"
 16 #Building statemant
 17 if ($usage2>6)
 18 print "Warning file system greater than 6% !!"
 19
 20 exit 0

ベストアンサー1

17行目は次のようになります。

if [ $usage2 -gt 6 ]

[前後にスペースを追加する必要があります]。また、数値を比較するときは、おなじみの記号の代わりに、、、、、およびを使用する-eq必要があります。-ne-gt-lt-ge-le

おすすめ記事