shell 判断文件是否存在,没有则创建

 

没有该文件则创建,有则 ls -l 输出文件信息。

#!/bin/bash
echo "enter the name:"
read filename
if test -e $filename ; then
ls -l $filename
else
touch $filename
fi

输出

enter the name:
sss.sh
-rwxr-xr-x 1 root root 147 Dec  3 09:02 sss.sh

 

posted @ 2018-12-07 23:00  anobscureretreat  阅读(2927)  评论(0编辑  收藏  举报