LoginSignup
14
10

More than 1 year has passed since last update.

Linux — シェルの変数を四則演算で計算する (足し算・引き算・掛け算・割り算)

Last updated at Posted at 2017-07-07

$((変数+変数)) みたいな記法を使う。

足し算

$ a=1; b=3; c=5; echo $((a+b+c));
9

引き算

$ a=1; b=3; c=5; echo $((a-b-c));
-7

掛け算

$ a=1; b=3; c=5; echo $((a*b*c));
15

割り算

小数点は出ないっぽい。

$ a=1; b=3; c=5; echo $((c/b));
1

環境

  • GNU bash, version 4.4.0(1)-release (x86_64-apple-darwin15.6.0)

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

14
10
1

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
14
10