shell判斷文件/目錄是否存在


https://www.cnblogs.com/37yan/p/6962563.html

 

caution!!! if should be end with fi

 

caution!!! there should be a space between [ and ! , also between 1 and ]

if [ ! $# -eq 1 ];then
#!/bin/bash
# 判斷傳入的參數的個數是不是一個
if [ ! $# -eq 1  ];then
  echo param error!
  exit 1
fi

# 判斷目錄是不是已經存在,如果不存在則創建,存在則輸出“dir exist” 
dirname=$1
echo "the dir name is $dirname"
if [ ! -d $dirname  ];then
  mkdir $dirname
else
  echo dir exist
fi

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM