#!/bin/bash
#程序31】
#题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续
# 判断第二个字母。
#1.程序分析:用情况语句比较好,如果第一个字母一样,则判断用情况语句或if语句判断第二个字母。
#2.程序源代码:
read letter
while [ "$letter" != 'Y' ];do
if [ "$letter" == 'S' ];then
echo "please input second letter:"
read letter
if [ "$letter" == 'a' ];then
echo 'Saturday'
elif [ $letter == 'u' ];then
echo 'Sunday'
else
echo 'data error'
break
fi
elif [ "$letter" == 'F' ];then
echo 'Friday'
elif [ "$letter" == 'M' ];then
echo 'Monday'
elif [ "$letter" == 'T' ];then
echo "please input second letter:"
read letter
if [ "$letter" == 'u' ];then
echo 'Tuesday'
elif [ "$letter" == 'h' ];then
echo 'Thursday'
else
echo 'data error'
break
fi
elif [ "$letter" == 'W' ];then
echo 'Wednesday'
else
echo 'data error'
break
fi
read letter
done
#!/bin/bash
#【程序32】
#题目:Press any key to change color, do you want to try it. Please hurry up!
#1.程序分析:
#2.程序源代码:
#Color Foreground Background
#black 30 40
#red 31 41
#green 32 42
#yellow 33 43
#blue 34 44
#magenta 35 45
#cyan 36 46
#white 37 47
for color in {40..47};do
read -p "Press any key to change color,do you want to try it? Please hurry up!"
echo -e "\e[1;${color}m \e[0m"
done
#!/bin/bash
#【程序33】
#题目:学习gotoxy()与clrscr()函数
#1.程序分析:
#2.程序源代码:
function gotoxy(){
local x=$1
local y=$2
printf '\033[%d;%dH' "$1" "$2"
}
for x in {0..10};do
gotoxy $x $(( 2*$x ))
echo "hello"
done
read -p "press any key to clear screen "
clear
#!/bin/bash
#【程序34】
#题目:练习函数调用
#1. 程序分析:
#2.程序源代码:
hello_world(){
echo "hello world"
}
three_hellos(){
for i in {0..2};do
hello_world
done
}
three_hellos
#!/bin/bash
#【程序35】
#题目:文本颜色设置
#1.程序分析:
#2.程序源代码:
#Color Foreground Background
#black 30 40
#red 31 41
#green 32 42
#yellow 33 43
#blue 34 44
#magenta 35 45
#cyan 36 46
#white 37 47
for color in {30..37};do
echo -e "\e[1;${color}mThis is a blue text.\e[0m"
done
阅读(711) | 评论(0) | 转发(1) |