新建腳本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