编写一个 Shell脚本,程序执行时从键盘读入一个目录名,如果用户输入的目录不存在,则提示file does not exist;如果用户输入的不是目录则提示用户必须输入目录名;如果用户输入的是目录则显示这个目录下所有文件的信息。
#!/bin/bash
read -p "please input a directory:" d
! [ -a "$d" ] && {
echo "file dose not exist"
exit 1
}
if [ -d "$d" ]
then
echo "is not a directory"
ls -l $d
exit 0
fi