shell 判斷是否是目錄


 

 

創建一個文件和一個文件夾

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!

 


免責聲明!

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



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