Checking if a file is readable and exists in one if condition: if [[ -r -f “/file.png” ]]

前端 未结 2 1890
死守一世寂寞
死守一世寂寞 2021-02-20 17:47

I was writing an if statement which checked if a file is readable and exists by doing the following:

if [[ -r \"$upFN\" && -f \"$upFN\" ]]; then
....
fi
         


        
2条回答
  •  孤独总比滥情好
    2021-02-20 18:02

    Is there ever a case where a file would be readable but it doesn't exist? Don't bother checking for existence when readability will tell you all you need.

提交回复
热议问题