3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Javaとシェルスクリプトの論理演算子・比較演算子を対比

Last updated at Posted at 2015-09-30

数値の比較演算

Java シェルスクリプト 備考
a == b a -eq b EQuals
シェスルクリプトで=と書くと文字列による比較になるので注意
a != b a -ne b Not Equals
シェスルクリプトで!=と書くと文字列による比較になるので注意
a > b a -gt b Greater Than
a < b a -lt b Less Than
a >= b a -ge b Greater or Equals
a <= b a -le b Less or Equals

文字列の比較演算

Java シェルスクリプト 備考
a.equals(b) a = b ==ではない
!a.equals(b) a != b
a.isEmpty()
a.length() == 0
-z a
!a.isEmpty()
a.length() > 0
-n a

論理演算

Java シェルスクリプト 備考
!a ![a] [!条件]ではなく![条件]
a && b [a] && [b] [条件1 && 条件2]ではなく[条件1] && [条件2]と記述する
a || b [a] || [b] [条件1 || 条件2]ではなく[条件1] || [条件2]と記述する
a & b [a] -a [b]
a | b [a] -o [b]
3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?