panyanbin / blog-comments

博客文章评论内容
0 stars 0 forks source link

Linux 文件判断(if [ -r file ]、if [ -e file ]) | 老潘的博客 #21

Open panyanbin opened 3 years ago

panyanbin commented 3 years ago

https://www.panyanbin.com/article/7e477c96.html

我们在编写shell脚本时,经常会根据某个文件的状态去处理不同的逻辑,比如一个文件不存在时的逻辑,若存在但是文件不可读又是其他的处理逻辑,这个时候就需要使用Linux的文件测试运算符进行判断。 文件测试运算符用于检测 Unix 文件的各种属性,其使用格式: 12345if [ operator file ]; then # 逻辑else # 其他逻辑fi