新建脚本1
从键盘输入用户名,是否存在,若存在,则进入用户目录。判断所有文件类型,并显示(for循环,不用file 命令)
脚本1
echo “ input the user name :”
read user
if grep $user /etc/passwd
then
cd $user
for i in *
do
if test -d $i
then
echo “ $i is mulu wenjian !”
elif test -f $i
then
echo “$i is putong wenjian !”
elif test -p $i
then
echo “$i is FIFO wenjian !”
elif test -b $i
then
echo “$i is kuaishebei wenjian !”
else
echo “$i is zifu shebei wenjian !”
fi
done
else
echo “ $user is not exits !”
fi
新建脚本2有9 个位置参数
用for循环判断那个是目录,普通文件,普通选项。
set /etc ls A `pwd` rm -r shiyan3-1.txt 89
for i in $*
do
if test -d $i
then
echo “$i is directory !”
elif test -f $i
then
echo “$i is common file !”
else
echo “$i is common option !”
fi
done
新建脚本3有两个位置参数,
$1是不是目录,若是,则看$2是否为文件,若是,则将$2复制到$1,打包压缩;若$1是文件, $2是目录,则将$1的内容复制到$2,打包压缩
set /root shiyan3-2.txt
if test -d $1
then
if test -f $2
then
cp $2 $1/copy1.txt
cd $1
tar zcvf bak1.gz copy1.txt
else
echo “can’t oprate 1 !”
fi
elif test –f $1
then
if test –d $2
then
cp $1 $2/copy2.txt
cd $2
tar zcvf bak2.gz copy2.txt
else
echo “can’t oprate 2 !”
fi
else
echo “can’t oprate 3 !”
fi