码迷,mamicode.com
首页 > 系统相关 > 详细

shell 判断是否是目录

时间:2018-12-08 00:18:22      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:not   The   file   div   touch   xxx   一个   执行   dir   

 

 

创建一个文件和一个文件夹

touch sss
mkdir d

test.sh

#!/bin/bash
echo "enter the name:"
read filename
if test -d $filename ; then
cd $filename
pwd
else
echo "it‘s not a directory!"
fi

 

执行

sudo chmod +x test.sh
./test.sh

输出

enter the name:
d
/home/xxx/Desktop/d

 

执行

./test.sh

输出

enter the name:
sss
its not a directory!

 

shell 判断是否是目录

标签:not   The   file   div   touch   xxx   一个   执行   dir   

原文地址:https://www.cnblogs.com/sea-stream/p/10085813.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!