1.思维导图
2.统计家目录下.c文件的个数
#!/bin/bash
count=`ls ~/*.c | wc -l`
echo $count
3.终端输入一个.sh文件,判断文件是否有可执行权限,如果有可执行权限运行脚本,没有可执行权限添加可执行权限后,再运行脚本
#!/bin/bash
read -p "请输入一个脚本文件名:" filename
if [ -x $filename ]
then
bash $filename
else
chmod a+x $filename
bash $filename
fi
4.写一个函数,输出当前用户uid和gid,并使用变量接收结果
#!/bin/bash
Output()
{
echo $(id -u)
echo $(id -g)
}
ret=`Output`
echo $ret
5.终端输入年月,判断该月有多少天,考虑闰平年的情况
#!/bin/bash
read -p "请输入年份:" year
echo
read -p "请输入月份:" month
case $month in
1|3|5|7|8|10|12)
echo "$year年$month月有31天"
;;
4|6|9|11)
echo "$year年$month月有30天"
;;
2)
if [ $((year%4)) -eq 0 -a $((year%100)) -ne 0 -o $((year%400)) -eq 0 ]
then
echo "$year年$month月有29天"
else
echo "$year年$month月有28天"
fi
;;
*)
echo "输入的月份错误"
esac
6.使用for循环,输出九九乘法表
#!/bin/bash
for ((i=1;i<=9;i++))
do
for ((j=1;j<=i;j++))
do
echo -n "$i*$j=$(($i*$j))" " "
done
echo
done
7.使用for循环,找到家目录下的所有.c文件,如果文件有内容编译该文件,如果文件中没有内容,删除文件
#!/bin/bash
for filename in `ls ~/*.c`
do
if [ -s ~/$filename ]
then
gcc $filename
echo "编译成功"
else
rm $filename
echo "删除成功"
fi
done