shell怎么判断文件是否存在

   2024-10-20 4430
核心提示:在shell中,可以使用-e参数来判断文件是否存在。下面是一个示例代码:#!/bin/bashfile=/path/to/file.txtif [ -e $file ]; thene

在shell中,可以使用-e参数来判断文件是否存在。下面是一个示例代码:

#!/bin/bashfile="/path/to/file.txt"if [ -e "$file" ]; then    echo "File exists"else    echo "File does not exist"fi

上面的代码会检查指定的文件是否存在,如果文件存在,则输出"File exists",否则输出"File does not exist"。

 
举报打赏
 
更多>同类网点查询
推荐图文
推荐网点查询
点击排行

网站首页  |  关于我们  |  联系方式网站留言    |  赣ICP备2021007278号