Difference between 'if -e' and 'if -f'

前端 未结 4 1283
南笙
南笙 2020-12-24 04:34

There are two switches for the if condition which check for a file: -e and -f.

What is the difference between those two?

4条回答
  •  -上瘾入骨i
    2020-12-24 05:31

    The if statement actually uses the program 'test' for the tests. You could write if statements two ways:

    if [ -e filename ];
    

    or

    if test -e filename;
    

    If you know this, you can easily check the man page for 'test' to find out the meanings of the different tests:

    man test
    

提交回复
热议问题