Question: Https://www.jinshuju.net/f/EGQL3D
Language: Shell (Bash)
Operation mode:
SH num-game.sh digit 1 digit 2 Number 3
If you do not want to use the method of passing numbers, you can modify num-game.sh line 9th to
num=$*
To
num= ' number 1 digit 2 digit 3 '
Then the direct operation of SH num-game.sh can
Copy Code code as follows:
#!/bin/bash
# # Author:taxkiz
# # Email:taxkiz@gmail.com
Export path= '/bin:/sbin:/usr/bin:/usr/sbin '
# # num= ' 3 5 7 '
num=$*
# # Check whether the number entered is 3
function CT () {
[$ (Echo $* | sed ' s//\n/g ' | wc-l)!= ' 3 '] && echo "please Enter 3 number!" && exit 1
}
CT $NUM
# # single Digit list
Nt= ' 1/2/3/4/5/6/7/8/9 '
# # Check if the number entered is a single-digit number
function CK () {
For num in $*
Todo
[$num = = ' 0 '] && echo "Error number ' $num '" && exit 2
echo $NT | grep "\b$num\b" >/dev/null 2>&1
[$?!= ' 0 '] && Echo ' $num is not a single digit ' && exit 3
Done
}
CK $NUM
# # To determine if there are duplicate numbers
function SN () {
If [$ = $] | | [$ = = $] | | [$ = $]; Then
echo "error! There have same number: ' $* '
Exit 4
Fi
}
SN $NUM
# # Yell A cry
function Go () {
A1=$1
A2=$2
A3=$3
t1=$ (($ * $))
t2=$ (($ * $))
t3=$ (($ * $))
ta=$ (($ * $))
For num in {1..100}
Todo
echo $num | grep $A 1 >/dev/null 2>&1
[$ = = ' 0 '] && Echo ' Fizz ' && continue
echo "scale=2; $num/$TA "| BC | grep >/dev/null 2>&1
[$ = = ' 0 '] && echo ' Fizzbuzzwhizz ' && continue
echo "scale=2; $num/$T 1 "| BC | grep >/dev/null 2>&1
[$ = = ' 0 '] && echo ' Fizzbuzz ' && continue
echo "scale=2; $num/$T 2 "| BC | grep >/dev/null 2>&1
[$ = = ' 0 '] && echo ' Buzzwhizz ' && continue
echo "scale=2; $num/$T 3 "| BC | grep >/dev/null 2>&1
[$ = = ' 0 '] && echo ' Fizzwhizz ' && continue
echo "scale=2; $num/$A 1 "| BC | grep >/dev/null 2>&1
[$ = = ' 0 '] && Echo ' Fizz ' && continue
echo "scale=2; $num/$A 2 "| BC | grep >/dev/null 2>&1
[$ = = ' 0 '] && echo ' Buzz ' && continue
echo "scale=2; $num/$A 3 "| BC | grep >/dev/null 2>&1
[$ = = ' 0 '] && echo ' Whizz ' && continue
Echo $num
Done
}
Go $NUM