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

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
it's not a directory!

shell 判断是否是目录的更多相关文章

  1. shell 判断文件、目录是否存在

    shell判断文件是否存在   1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. m ...

  2. centos shell脚本编程1 正则 shell脚本结构 read命令 date命令的用法 shell中的逻辑判断 if 判断文件、目录属性 shell数组简单用法 $( ) 和${ } 和$(( )) 与 sh -n sh -x sh -v 第三十五节课

    centos   shell脚本编程1 正则  shell脚本结构  read命令  date命令的用法  shell中的逻辑判断  if 判断文件.目录属性  shell数组简单用法 $( ) 和$ ...

  3. shell判断文件,目录是否存在或者具有权限的代码

    核心代码 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的 ...

  4. shell判断文件,目录是否存在或者具有权限 (转载)

    转自:http://cqfish.blog.51cto.com/622299/187188 文章来源:http://hi.baidu.com/haigang/blog/item/e5f582262d6 ...

  5. shell判断文件,目录是否存在或者具有权限

    shell判断文件,目录是否存在或者具有权限  #!/bin/sh  myPath="/var/log/httpd/"  myFile="/var /log/httpd/ ...

  6. linux shell判断文件,目录是否存在或者具有权限

    在linux中判断文件,目录是否存在或则具有的权限,根据最近的学习以及网上的资料,进行了以下的总结: #!/bin/sh myPath="/var/log/httpd/" myFi ...

  7. shell判断文件是否存在

    转自:http://www.cnblogs.com/sunyubo/archive/2011/10/17/2282047.html 1. shell判断文件,目录是否存在或者具有权限 2. #!/bi ...

  8. Linux shell判断文件和文件夹是否存在

    shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...

  9. shell判断条件是否存在

    1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. myFile="/var ...

随机推荐

  1. idea创建maven多应用工程

    新建一个project ,名称为ismp,新建三个module,一个公共依赖module common,一个web module adminweb,一个java后台类 user; 目录结构如下: 如果 ...

  2. mysql动态sql 整理多个字段

    原始表: 整理后的表: 方案一(动态sql): BEGIN #Routine body goes here... DECLARE v1 ); DECLARE v2 ); #DECLARE v3 VAR ...

  3. 170726、常用 Git 命令清单

    ,下面是我整理的常用 Git 命令清单.几个专用名词的译名如下: Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remote:远程仓库 一 ...

  4. Oracle下where子句

    课外题 要求:删除某一个用户,同时保留该用户的数据?如何解决 alter user scott account lock :改天需要使用则解锁unlock 锁定用户使用sysdba登录还是可以查看数据 ...

  5. python的tqdm模块

    Tqdm 是一个快速,可扩展的Python进度条,可以在 Python 长循环中添加一个进度提示信息,用户只需要封装任意的迭代器 tqdm(iterator). 根据要求安装依赖即可. 可以很方便的在 ...

  6. python笔记9-多线程Threading之阻塞(join)和守护线程(setDaemon)

    python笔记9-多线程Threading之阻塞(join)和守护线程(setDaemon) 前言 今天小编YOYO请xiaoming和xiaowang吃火锅,吃完火锅的时候会有以下三种场景: - ...

  7. Portugal 2 1 minute has Pipansihuan Germany and USA tacit or kick the ball

    C Luo assists last moment so that Portugal "back to life", but with just two games to allo ...

  8. android 模仿今日头条ViewPager+TabLayout

    导入依赖库: compile 'com.android.support:design:25.3.1' 1.fg_content_demo2.xml <?xml version="1.0 ...

  9. 001-java虚拟机的概念

    https://blog.csdn.net/yfqnihao/article/details/8289363 1.什么是java虚拟机.(你以为你知道,如果你看我下面的例子,你会发现你其实不知道) ( ...

  10. 《大话设计模式》ruby版代码:外观模式

    需求: 股民买卖股票 初步代码: # -*- encoding: utf-8 -*- #股票1 class Stock1 def buy puts '股票1买入' end def sell puts ...