Bash 脚本乘法 table
Bash Scripting Multiplication table
您好,我想知道是否有人可以帮助我:
我想给我女儿做一个乘法table,我不知道怎么做。这就是我想要的样子:
1 × 1 =?回答
如果答案为真,则转到下一个
1×2 =?
但如果答案为假,则再问一次 1 x 1 = ?
直到答案正确。
#!/bin/bash
# Multiplication table
echo " --== Multiplication Table ==-- "
sleep 2
echo " Lesson 1"
sleep 1
echo ""
echo -n "1 x 1 = ? " ; read opt
if [ "$opt" = 1 ]
then
echo "Correct!"
else
echo "Wrong!"
fi
sleep 1
echo ""
echo -n "1 x 2 = ? " ; read opt
if [ "$opt" = 2 ]
then
echo "Correct!"
else
echo "Wrong!"
fi
练习结束后到10点。然后显示正确答案和错误答案的结果。
例子:
第 1 课已完成,您有 9 个正确答案和 1 个错误答案!
您可以使用这个脚本:
#!/bin/bash
# Multiplication table
echo " --== Multiplication Table ==-- "
sleep 2
echo " Lesson "
sleep 1
echo ""
wrong=0
correct=0
for i in {1..10}
do
while true
do
echo -n " x $i = ? " ; read opt
if [ $opt = $(( * $i )) ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
done
echo "Lesson is finish you have $correct correct answers and $wrong wrong answer!"
您可以 运行 为任何基地设置不同的参数。例如 ./script 5
与 5 相乘。
我做到了。这就是我想要的样子和工作方式
#!/bin/bash
# Multiplication table
echo " --== Multiplication Table ==-- "
sleep 2
echo " Lesson 1"
sleep 1
echo ""
while true
do
echo -n "1 x 1 = ? " ; read opt
if [ $opt = 1 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 2 = ? " ; read opt
if [ $opt = 2 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 3 = ? " ; read opt
if [ $opt = 3 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 4 = ? " ; read opt
if [ $opt = 4 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 5 = ? " ; read opt
if [ $opt = 5 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 6 = ? " ; read opt
if [ $opt = 6 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 7 = ? " ; read opt
if [ $opt = 7 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 8 = ? " ; read opt
if [ $opt = 8 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 9 = ? " ; read opt
if [ $opt = 9 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 10 = ? " ; read opt
if [ $opt = 10 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
echo "Lesson 1 is finish you have $correct correct answers and $wrong wrong answer!"
#!/bin/bash
#######multiplication table#########
INPUT_NUMBER=
if [[ $# -ne 1 ]]; then
echo "please enter at least 1 number"
exit 1
fi
if [[ ! ${INPUT_NUMBER} =~ [[:digit:]] ]];then
echo "Incorrect usage, wrong type args"
echo "Usage is [=10=] <number>"
exit 1
fi
for i in {1..10}
do
echo "${INPUT_NUMBER} * ${i} = $((${INPUT_NUMBER} * ${i}))"
done
您好,我想知道是否有人可以帮助我: 我想给我女儿做一个乘法table,我不知道怎么做。这就是我想要的样子: 1 × 1 =?回答 如果答案为真,则转到下一个 1×2 =? 但如果答案为假,则再问一次 1 x 1 = ? 直到答案正确。
#!/bin/bash
# Multiplication table
echo " --== Multiplication Table ==-- "
sleep 2
echo " Lesson 1"
sleep 1
echo ""
echo -n "1 x 1 = ? " ; read opt
if [ "$opt" = 1 ]
then
echo "Correct!"
else
echo "Wrong!"
fi
sleep 1
echo ""
echo -n "1 x 2 = ? " ; read opt
if [ "$opt" = 2 ]
then
echo "Correct!"
else
echo "Wrong!"
fi
练习结束后到10点。然后显示正确答案和错误答案的结果。 例子: 第 1 课已完成,您有 9 个正确答案和 1 个错误答案!
您可以使用这个脚本:
#!/bin/bash
# Multiplication table
echo " --== Multiplication Table ==-- "
sleep 2
echo " Lesson "
sleep 1
echo ""
wrong=0
correct=0
for i in {1..10}
do
while true
do
echo -n " x $i = ? " ; read opt
if [ $opt = $(( * $i )) ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
done
echo "Lesson is finish you have $correct correct answers and $wrong wrong answer!"
您可以 运行 为任何基地设置不同的参数。例如 ./script 5
与 5 相乘。
我做到了。这就是我想要的样子和工作方式
#!/bin/bash
# Multiplication table
echo " --== Multiplication Table ==-- "
sleep 2
echo " Lesson 1"
sleep 1
echo ""
while true
do
echo -n "1 x 1 = ? " ; read opt
if [ $opt = 1 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 2 = ? " ; read opt
if [ $opt = 2 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 3 = ? " ; read opt
if [ $opt = 3 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 4 = ? " ; read opt
if [ $opt = 4 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 5 = ? " ; read opt
if [ $opt = 5 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 6 = ? " ; read opt
if [ $opt = 6 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 7 = ? " ; read opt
if [ $opt = 7 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 8 = ? " ; read opt
if [ $opt = 8 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 9 = ? " ; read opt
if [ $opt = 9 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
while true
do
echo -n "1 x 10 = ? " ; read opt
if [ $opt = 10 ]
then
(( correct++ ))
echo "Correct!"
break
else
(( wrong++ ))
echo "Wrong!"
fi
done
echo "Lesson 1 is finish you have $correct correct answers and $wrong wrong answer!"
#!/bin/bash
#######multiplication table#########
INPUT_NUMBER=
if [[ $# -ne 1 ]]; then
echo "please enter at least 1 number"
exit 1
fi
if [[ ! ${INPUT_NUMBER} =~ [[:digit:]] ]];then
echo "Incorrect usage, wrong type args"
echo "Usage is [=10=] <number>"
exit 1
fi
for i in {1..10}
do
echo "${INPUT_NUMBER} * ${i} = $((${INPUT_NUMBER} * ${i}))"
done