这里的意思是什么-x
:
if [ -x /etc/rc.local ] then
我怎样才能找到这个手册页if
?
答案1
从man bash
页面(特别是条件表达式部分):
-a file
True if file exists.
-b file
True if file exists and is a block special file.
-c file
True if file exists and is a character special file.
-d file
True if file exists and is a directory.
-e file
True if file exists.
-f file
True if file exists and is a regular file.
-g file
True if file exists and is set-group-id.
-h file
True if file exists and is a symbolic link.
-k file
True if file exists and its ``sticky'' bit is set.
-p file
True if file exists and is a named pipe (FIFO).
-r file
True if file exists and is readable.
-s file
True if file exists and has a size greater than zero.
-t fd True if file descriptor fd is open and refers to a terminal.
-u file
True if file exists and its set-user-id bit is set.
-w file
True if file exists and is writable.
-x file
True if file exists and is executable.
[...]
答案2
if
本身是一个 shell 关键字,因此您可以使用 查找有关它的信息help if
。 if
本身仅根据下一个命令返回 true ( 0 ) 还是 false ( 而不是 zero ) 进行分支。但您真正想要的是man [
或man test
,其中[
是 的别名test
。该语句实际上是在执行test -x /etc/rc.local
,它测试该文件是否存在且是否可执行(或具有搜索权限)。
答案3
从info test
:
`-x FILE'
True if FILE exists and execute permission is granted (or search permission, if it is a directory).
需要对目录具有执行权限才能通过 cd 进入该目录(也就是说,使某个目录成为当前工作目录)。
需要对目录执行权限才能访问其中文件的“inode”信息。您需要执行权限才能搜索目录以读取其中文件的 inode。因此,目录上的执行权限通常被称为搜索权限。