祁连踏雪 阳关揽月 扬鞭踏马胭脂山 踩沙逐浪黑河岸 分享 http://blog.sciencenet.cn/u/shenxzh

博文

check the existance of a directory in a bash shell

已有 3000 次阅读 2012-2-1 15:18 |个人分类:Shell scripts|系统分类:科研笔记

To check if a directory exists in a bash shell script you can use the following:

if [ -d "$DIRECTORY" ]; then # Control will enter here if $DIRECTORY exists fi

Or to check if a directory doesn't exist:

if [ ! -d "$DIRECTORY" ]; then # Control will enter here if $DIRECTORY doesn't exist fi

if [ -d "$LINK_OR_DIR" ]; then if [ -L "$LINK_OR_DIR" ]; then # It is a symlink! # Symbolic link specific commands go here rm "$LINK_OR_DIR" else # It's a directory! # Directory command goes here rmdir "$LINK_OR_DIR" fi fi

https://blog.sciencenet.cn/blog-381041-533340.html

上一篇:雾里兰州
下一篇:Convert the string to number and compare
收藏 IP: 202.100.91.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-12-22 14:49

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部