0
0

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.

Bashで3パターンのおみくじを作った

Posted at

はじめに

シェルスクリプトの学習として作りました。
作ったおみくじはifを使ったもの、caseを使ったもの、配列を使ったものの3パターンです。

ifを使ったおみくじ

# !/bin/bash

number=$(($RANDOM%6))

if [ $number -eq 0 ]; then
        echo 大吉
elif [ $number -eq 1 ]; then
        echo 中吉
elif [ $number -eq 2 ]; then
        echo 小吉
elif [ $number -eq 3 ]; then
        echo 末吉
elif [ $number -eq 4 ]; then
        echo else
        echo 大凶
fi

caseを使ったおみくじ

# !/bin/bash

number=$(($RANDOM%6))

case "$number" in
        0)
                echo 大吉
                ;;
        1)
                echo 中吉
                ;;
        2)
                echo 小吉
                ;;
        3)
                echo 末吉
                ;;
        4)
                echo ;;
        5)
                echo 大凶
                ;;
esac

配列を使ったおみくじ

# !/bin/bash

f=("大吉" "中吉" "小吉" "末吉" "凶" "大凶")
num=$(($RANDOM%6))

echo ${f[$num]}

以上です

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?