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