Unix-boolean-operators
提供:Dev Guides
Unix/Linux-シェルブール演算子の例
次のブール演算子は、Bourne Shellでサポートされています。
変数 a が10を保持し、変数 b が20を保持すると仮定します-
Operator | Description | Example |
---|---|---|
! | This is logical negation. This inverts a true condition into false and vice versa. | [ ! false ] is true. |
*-o * | This is logical* OR*. If one of the operands is true, then the condition becomes true. | [ $a -lt 20 -o $b -gt 100 ] is true. |
*-a * | This is logical* AND*. If both the operands are true, then the condition becomes true otherwise false. | [ $a -lt 20 -a $b -gt 100 ] is false. |
例
これは、すべてのブール演算子を使用する例です-
上記のスクリプトは、次の結果を生成します-
演算子を使用しながら、次の点を考慮する必要があります-
- 演算子と式の間にはスペースが必要です。 たとえば、2+ 2は正しくありません。 2+と書く必要があります。 2。
- if … then … else … fi ステートメントは、次の章で説明されている意思決定ステートメントです。