1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

シェルスクリプトで変数に数値を代入した使い方

Last updated at Posted at 2024-11-28

変数に数値を入れて比較したい

シェルスクリプトで数値を変数に代入した使い方を調べてみました。

以下の通りに書いてみます。

#!/bin/bash

a="熱い"
b="涼しい"

kion=18

if [[ "${kion}" > 20 ]]; then
echo $a
else
echo $b
fi

変数「kion」に数値を代入した後、条件文で比較しています。
条件文の中での変数の書き方は特徴があります。

実行結果は以下の通りです。

涼しい
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?