Created
January 27, 2020 07:00
-
-
Save td-shi/809555a20c48db8db04385ee21c820e3 to your computer and use it in GitHub Desktop.
I bought tarot cards, also this script was made.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash --posix | |
# -*- coding:utf-8 -*- | |
# === Coding shell scripting Memo ============================================== | |
# ${<name>#<pattern>} :: matching delete with shortest by forword. | |
# ${<name>##<pattern>} :: matching delete with longest by forword. | |
# ${<name>%<pattern>} :: matching delete with shortest by backword. | |
# ${<name>%%<pattern>} :: mathing delete with longest by backword. | |
# ${<name>/<before>/<after>} :: replace only first matching. | |
# ${<name>//<before>/<after>} :: replace all matching. | |
# ${<name>:-<value>} :: if no yet set value, return value. | |
# ${<name>:=<value>} :: if no yet set value, return value and set. | |
# ". <shell script>" is to keep current shell and take over environment. | |
# === Initialize shell environment ============================================= | |
#set -u # Just stop undefined values. | |
#set -e # Just stop error. | |
#set -x # Debug running command. | |
umask 0022 | |
export LC_ALL=C | |
export LANG=C | |
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:${PATH+:}${PATH-}" | |
type command >/dev/null 2>&1 && type getconf >/dev/null 2>&1 && | |
export PATH="$(command -p getconf PATH):${PATH}" | |
export UNIX_STD=2003 # to make HP-UX conform to POSIX | |
# === Define the functions for printing usage and error message ================ | |
usage_and_exit(){ | |
cat <<-" USAGE" 1>&2 | |
tarot.sh return tarot card. | |
Usage : tarot.sh [options] | |
Options : | |
-h |--help |--version | |
This help. | |
-N <num> | |
Returning nums cards. | |
Version : 2020-01-05_15:03:41 0.01 | |
LICENSE : CC0 | |
This is a public-domain software (CC0). It means that | |
all of the people can use this for any purposes with no | |
restrictions at all. By the way, We are fed up with the | |
side effects which are brought about by the major licenses. | |
Author : 2020 TD | |
USAGE | |
exit 1 | |
} | |
error_exit() { | |
${2+:} false && echo "${0##*/}: $2" 1>&2 | |
exit "$1" | |
} | |
# === Initialize parameters ==================================================== | |
# Detect home directory of this app. and define more | |
#Homedir="$(d=${0%/*}/; [ "_$d" = "_$0/" ] && d='./'; cd "$d.."; pwd)" | |
#PATH="$Homedir/<Add Dir>:$PATH" # for additional command | |
#. "$Homedir/<shell script config-file.>" # configration value. | |
FOOL=0 | |
MAGICIAN=0 | |
PRIESTESS=0 | |
EMPRESS=0 | |
EMPEROR=0 | |
HIEROPHANT=0 | |
LOVERS=0 | |
CHARIOT=0 | |
STRENGTH=0 | |
HERMIT=0 | |
FORTUNE=0 | |
JUSTICE=0 | |
HANGEDMAN=0 | |
DEATH=0 | |
TEMPERANCE=0 | |
DEVIL=0 | |
TOWER=0 | |
STAR=0 | |
MOON=0 | |
SUN=0 | |
JUDGEMENT=0 | |
WORLD=0 | |
FULLSUM=0 | |
NUMS=1 | |
DECK="" | |
# === Confirm that the required commands exist ================================= | |
# --- cURL or Wget (exsample) | |
#if type curl >/dev/null 2>&1; then | |
# CMD_CURL='curl' | |
#elif type wget >/dev/null 2>&1; then | |
# CMD_WGET='wget' | |
#else | |
# error_exit 1 'No HTTP-GET/POST command found.' | |
#fi | |
# === Print usage and exit if one of the help options is set =================== | |
case "$# ${1:-}" in | |
'1 -h'|'1 --help'|'1 --version') usage_and_exit;; | |
esac | |
# === Read options ============================================================= | |
while :; do | |
case "${1:-}" in | |
-N) | |
NUMS=$(printf '%s' "${2:-}" | tr -d '\n') | |
if [ "${NUMS}" -ge 1 ] && [ "${NUMS}" -le 22 ]; then | |
: | |
else | |
error_exit 1 'The arg N is only integer, 1 <= N <= 22.' | |
fi | |
shift 2 | |
;; | |
--|-) | |
break | |
;; | |
--*|-*) | |
error_exit 1 'Invalid option' | |
;; | |
*) | |
break | |
;; | |
esac | |
done | |
# === Require parameters check ================================================= | |
#printf '%s\n' "${zzz}" | grep -Eq '^$|^-?[0-9.]+,-?[0-9.]+$' || { | |
# error_exit 1 'Invalid -l,--location option' | |
#} | |
# === Last parameter =========================================================== | |
#case $# in | |
# 0) <input>=$(cat -) | |
# ;; | |
# 1) case "${1:-}" in | |
# '--') usage_and_exit;; | |
# '-') <input>=$(cat -) ;; | |
# *) <input>=$1 ;; | |
# esac | |
# ;; | |
# *) case "$1" in '--') shift;; esac | |
# <input>="$*" | |
# ;; | |
#esac # Escape 0x0A to 0x1E | |
# === Define funcitons ========================================================= | |
# === Main routine ============================================================= | |
while [ ${FULLSUM} -lt 4194303 ]; do | |
PPP=256 | |
REV="R" | |
while [ ${PPP} -ge 242 ]; do | |
PPP=$(od -A n -t u1 -N 1 /dev/urandom) | |
if [ "R" = ${REV} ]; then | |
REV="F" | |
else | |
REV="R" | |
fi | |
done | |
PPP=$(( PPP % 22 )) | |
case ${PPP} in | |
0) | |
if [ ${FOOL} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "0 FOOL\n") | |
FOOL=1 | |
FULLSUM=$((FULLSUM + 1)) | |
fi | |
;; | |
1) | |
if [ ${MAGICIAN} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "1 MAGICIAN\n") | |
MAGICIAN=1 | |
FULLSUM=$((FULLSUM + 2)) | |
fi | |
;; | |
2) | |
if [ ${PRIESTESS} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "2 PRIESTESS\n") | |
PRIESTESS=1 | |
FULLSUM=$((FULLSUM + 4)) | |
fi | |
;; | |
3) | |
if [ ${EMPRESS} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "3 EMPRESS\n") | |
EMPRESS=1 | |
FULLSUM=$((FULLSUM + 8)) | |
fi | |
;; | |
4) | |
if [ ${EMPEROR} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "4 EMPEROR\n") | |
EMPEROR=1 | |
FULLSUM=$((FULLSUM + 16)) | |
fi | |
;; | |
5) | |
if [ ${HIEROPHANT} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "5 HIEROPHANT\n") | |
HIEROPHANT=1 | |
FULLSUM=$((FULLSUM + 32)) | |
fi | |
;; | |
6) | |
if [ ${LOVERS} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "6 LOVERS\n") | |
LOVERS=1 | |
FULLSUM=$((FULLSUM + 64)) | |
fi | |
;; | |
7) | |
if [ ${CHARIOT} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "7 CHARIOT\n") | |
CHARIOT=1 | |
FULLSUM=$((FULLSUM + 128)) | |
fi | |
;; | |
8) | |
if [ ${STRENGTH} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "8 STRENGTH\n") | |
STRENGTH=1 | |
FULLSUM=$((FULLSUM + 256)) | |
fi | |
;; | |
9) | |
if [ ${HERMIT} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "9 HERMIT\n") | |
HERMIT=1 | |
FULLSUM=$((FULLSUM + 512)) | |
fi | |
;; | |
10) | |
if [ ${FORTUNE} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "10 FORTUNE\n") | |
FORTUNE=1 | |
FULLSUM=$((FULLSUM + 1024)) | |
fi | |
;; | |
11) | |
if [ ${JUSTICE} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "11 JUSTICE\n") | |
JUSTICE=1 | |
FULLSUM=$((FULLSUM + 2048)) | |
fi | |
;; | |
12) | |
if [ ${HANGEDMAN} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "12 HANGEDMAN\n") | |
HANGEDMAN=1 | |
FULLSUM=$((FULLSUM + 4096)) | |
fi | |
;; | |
13) | |
if [ ${DEATH} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "13 DEATH\n") | |
DEATH=1 | |
FULLSUM=$((FULLSUM + 8192)) | |
fi | |
;; | |
14) | |
if [ ${TEMPERANCE} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "14 TEMPERANCE\n") | |
TEMPERANCE=1 | |
FULLSUM=$((FULLSUM + 16384)) | |
fi | |
;; | |
15) | |
if [ ${DEVIL} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "15 DEVIL\n") | |
DEVIL=1 | |
FULLSUM=$((FULLSUM + 32768)) | |
fi | |
;; | |
16) | |
if [ ${TOWER} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "16 TOWER\n") | |
TOWER=1 | |
FULLSUM=$((FULLSUM + 65536)) | |
fi | |
;; | |
17) | |
if [ ${STAR} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "17 STAR\n") | |
STAR=1 | |
FULLSUM=$((FULLSUM + 131072)) | |
fi | |
;; | |
18) | |
if [ ${MOON} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "18 MOON\n") | |
MOON=1 | |
FULLSUM=$((FULLSUM + 262144)) | |
fi | |
;; | |
19) | |
if [ ${SUN} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "19 SUN\n") | |
SUN=1 | |
FULLSUM=$((FULLSUM + 524288)) | |
fi | |
;; | |
20) | |
if [ ${JUDGEMENT} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "20 JUDGEMENT\n") | |
JUDGEMENT=1 | |
FULLSUM=$((FULLSUM + 1048576)) | |
fi | |
;; | |
21) | |
if [ ${WORLD} -eq 0 ]; then | |
DECK=$(printf "%s%s %s" "${DECK}" "${REV}" "21 WORLD\n") | |
WORLD=1 | |
FULLSUM=$((FULLSUM + 2097152)) | |
fi | |
;; | |
*) ;; | |
esac | |
done | |
printf "%b" "${DECK}" | head -"${NUMS}" | |
# === End shell script ========================================================= | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment