输入目录名,显示目录下所有内容.

xiaoxiao2021-02-28  48

read -p"please input a filename!" -t 30 filename

 

if [ -z $filename];then

        echo "please input!!!!!!"

        exit 1

fi

#如果字符串为空,报错跳出

 

if [ ! -e $filename]

        then

                echo "$filename notcunzai!!"

                exit 2

fi

#如果文件不存在,报错跳出

 

if [ ! -d $filename]

        then

                echo "$filename is notdriectory"

                exit 3

fi

#如果不是目录,报错跳出

 

file=`ls $filename`

 

for test in $file

        do

                echo $test

        done

转载请注明原文地址: https://www.6miu.com/read-2631754.html

最新回复(0)