区别,如果-e如果-f之间 [英] Difference between if -e and if -f
问题描述
我有一个简单的问题,但我找不到任何答案。有2个开关,用于if条件里面做检查的文件,-e和-f。什么是这两者之间的区别?
I have a simple question, but I couldn't find any answer to it. There are 2 switches for the if condition which do check for a file, -e and -f. What's the difference between those two?
推荐答案
请参阅:<一href=\"http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html\">http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
我认为这些都不是如果开关,而测试开关(因为你必须使用它们的内部括号[]。
I believe those aren't "if switches", rather "test switches" (because you have to use them inside [] brackets.
但不同的是:
[-e FILE]
真如果文件存在。
这将返回真正为 / etc / hosts中
和的/ dev / null的
。
[-f FILE]
如果FILE存在且是一个普通文件则为真。
这将返回真正为 / etc / hosts中
和假为的/ dev / null的
(因为它不是一个普通的文件)。
[ -f FILE ]
True if FILE exists and is a regular file.
This will return true for /etc/hosts
and false for /dev/null
(because it is not a regular file).
这篇关于区别,如果-e如果-f之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!