1.思维导图:
2.
#!/bin/bash
read -p "please enter file:" file
if [ -e ./$file ]
then
if [ -d $file ]
then
echo 是目录文件
elif [ -f $file ]
then
if [ -w $file -a -r $file -a -x $file ]
then
echo hello >> $file
echo `cat $file`
else
chmod 777 $file
echo hello >> $file
echo `cat $file`
fi
fi
else
echo error
fi
if [ -L ./$file ]
then
echo `ls -lh $file`
fi
3.
#!/bin/bash
read -p "please enter an number:" a
for((i=1;i<=${#a};i++))
do
b=$b${a:0-$i:1}
done
echo $b
if [ $b -eq $a ]
then
echo yes
else
echo no
fi
4.
#!/bin/bash
read -p "please enter n:" n
if [ $n -eq 0 ]
then
echo 1
else
a=1
for((i=1;i<=n;i++))
do
((a*=i))
done
echo $a
fi
5.
#!/bin/bash
for((i=1;i<=4;i++))
do
for((j=0;j<=4-i;j++))
do
echo -n " "
done
for((k=0;k<2*i-1;k++))
do
echo -n "*"
done
echo ""
done
6.
#!/bin/bash
arr=(Windows Linux Unix Mac)
i=
select a in ${arr[*]}
do
case $a in
"Windows")
echo Windows以打开
;;
"Linux")
echo Linux以打开
;;
"Unix")
echo Unix以打开
;;
"Max")
echo Max以打开
;;
*)
echo error
;;
esac
((i++))
done
7.
#!/bin/bash
read -p "please enter a:" a
for((i=2;i<a;i++))
do
if [ $(($a%$i)) -ne 0 ]
then
echo 是素数
else
echo 不是素数
break
fi
done