Shell程序荟萃
--------------纯输出----------------1.sh
#!/bin/sh
echo -e "Hello!world!\a\n"
exit 0
--------------获得用户输入----------------2.sh
#!/bin/sh
read -p "Please input your name:" name
echo -e "\nHello!$name"
exit 0
--------------日期计算昨天今天明天----------------3.sh
#!/bin/sh
yesterday=$(date --date='1 days ago' +%Y/%m/%d)
today=$(date +%Y%m%d)
tomorrow=$(date -d '1 days' +%Y-%m-%d)
echo -e "Yesterday is $yesterday"
echo -e "Today is $today"
echo -e "Tomorrow is $tomorrow"
exit 0
--------------100以内加减法计算游戏----------------4.sh
#!/bin/sh
declare -i rnd1=$RANDOM
declare -i rnd2=$RANDOM
op1=$(( $rnd1%100 ))
op2=$(( $rnd2%100 ))
if [ $op2 -gt $op1 ]; then
op3=$op2
op2=$op1
op1=$op3
fi
op4=$(( $op1%2 ))
if [ $op4 == 1 ]; then
result=$(( $op1+$op2 ))
read -p "$op1+$op2=" resp
if [ $result == $resp ]; then
echo " v"
else
echo " x"
fi
else
result=$(( $op1-$op2 ))
read -p "$op1-$op2=" resp
if [ $result == $resp ]; then
echo " v"
else
echo " x"
fi
fi
exit 0
--------------待续----------------