Emi*_*tai 69
请参阅:http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
我相信那些不是"如果开关",而是"测试开关"(因为你必须在[]括号内使用它们.
但不同的是:
[ -e FILE ] 如果存在FILE,则为True.
对于两者而言,这将返回true./etc/hosts/dev/null
[ -f FILE ]如果FILE存在且为常规文件,则为True.这将返回真实的/etc/hosts和虚假的/dev/null(因为它不是一个普通的文件).
jma*_*man 35
$ man bash
-e file
True if file exists.
-f file
True if file exists and is a regular file.
Run Code Online (Sandbox Code Playgroud)
常规文件不是目录/符号链接/套接字/设备等.
if 语句实际上使用程序“test”进行测试。您可以通过两种方式编写 if 语句:
if [ -e filename ];
Run Code Online (Sandbox Code Playgroud)
或者
if test -e filename;
Run Code Online (Sandbox Code Playgroud)
如果您知道这一点,您可以轻松查看“test”的手册页以找出不同测试的含义:
man test
Run Code Online (Sandbox Code Playgroud)