练习1:输入一个数,实现倒叙123-》321
练习2:输入一个,判断是否是素数
练习3:输入一个文件名,
判断是否在家目录下存在,
如果是一个目录,则直接输出是目录下的sh文件的个数
如果存在则判断是否是一个普通文件,如果是普通文件则判断是否具备
可读可写可执行权限,如果具备权限,写入helo.不具备权限,则添加读写执行权限,写入hello
#!/bin/bash
read -p "请输入文件名:" a
if [ -e $a ] #默认是家目录下
then
echo "$a存在"
#
if [ -b $a ]
then
echo "块设备文件"
if [ -r $a ]
then
echo -n "r"
else
echo -n "-"
fi
if [ -w $a ]
then
echo -n "w"
else
echo -n "-"
fi
if [ -x $a ]
then
echo -n "x"
else
echo -n "-"
fi
#
elif [ -c $a ]
then
echo "字符文件"
if [ -r $a ]
then
echo -n "r"
else
echo -n "-"
fi
if [ -w $a ]
then
echo -n "w"
else
echo -n "-"
fi
if [ -x $a ]
then
echo -n "x"
else
echo -n "-"
fi
#
elif [ -d $a ]
then
echo "目录文件"
if [ -r $a ]
then
echo -n "r"
else
echo -n "-"
fi
if [ -w $a ]
then
echo -n "w"
else
echo -n "-"
fi
if [ -x $a ]
then
echo -n "x"
else
echo -n "-"
fi
#
elif [ -L $a ]
then
echo "软链接文件"
if [ -r $a ]
then
echo -n "r"
else
echo -n "-"
fi
if [ -w $a ]
then
echo -n "w"
else
echo -n "-"
fi
if [ -x $a ]
then
echo -n "x"
else
echo -n "-"
fi
#
elif [ -S $a ]
then
echo "套接字文件"
if [ -r $a ]
then
echo -n "r"
else
echo -n "-"
fi
if [ -w $a ]
then
echo -n "w"
else
echo -n "-"
fi
if [ -x $a ]
then
echo -n "x"
else
echo -n "-"
fi
elif [ -p $a ]
then
echo "管道文件"
if [ -r $a ]
then
echo -n "r"
else
echo -n "-"
fi
if [ -w $a ]
then
echo -n "w"
else
echo -n "-"
fi
if [ -x $a ]
then
echo -n "x"
else
echo -n "-"
fi
elif [ -f $a ]
then
echo "普通文件"
if [ -r $a ]
then
echo -n "r"
else
echo -n "-"
fi
if [ -w $a ]
then
echo -n "w"
else
echo -n "-"
fi
if [ -x $a ]
then
echo -n "x"
else
echo -n "-"
fi
fi
else
echo "$a不存在"
fi
练习4:输入一个字符串,实现字符串逆置