-x 在 if 条件语句中是什么意思?

tay*_*oon 28 command-line bash

-x这里是什么意思:

if [ -x /etc/rc.local ] then
Run Code Online (Sandbox Code Playgroud)

我怎么能找到这个手册页if

Syl*_*eau 37

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.

   [...]
Run Code Online (Sandbox Code Playgroud)

  • 需要注意的是,一个目录的可执行意味着它可以被遍历。 (4认同)
  • @StevenPenny 问题的第二部分是“如果我怎么能找到这个手册页?” (2认同)

psu*_*usi 11

if本身是一个 shell 关键字,因此您可以使用help if. if本身仅根据下一个命令返回 true ( 0 ) 还是 false ( 非零) 来进行分支。不过,您真正想要的是man [or man test, where[test. 该语句实际上正在执行test -x /etc/rc.local,它测试该文件是否存在并且是否可执行(或具有搜索权限)。