bash 中的各种标志

问题描述 投票:0回答:2

我多次看到诸如

if [-n ${Parameter}]
echo -n <string>
之类的标志。有时,我看到过类似
-r
等标志的使用。但是,我不知道如何在网络上搜索这些标志的含义。有人可以给我发送一些链接,让我可以理解它们的含义,或者一些关于我应该如何在谷歌上搜索它们的一般说明吗?谢谢!

bash flags
2个回答
4
投票

您当然可以在互联网上查看文档https://ss64.com/bash/if.html

或者,如果您可以访问 Linux 或 Mac 计算机,只需查看已安装的文档即可!

例如尝试

man if

此外,

man
可以有多个页面用于同一查询,例如
man open
将在我的机器上显示openvt的手册,并且是命令行可执行文件。但是写
man 2 open
会给你C open函数的手册。 所以默认情况下,man 会给你 bash/命令行手册,然后是 C 函数。 所以
man open
可以写成
man 1 open

如果您无法访问互联网或者您想要使用的工具版本与“正常”版本不同,这非常有用。例如,我认为 sed 与 linux 和 mac 不同。所以他们有不同的手册。

当然有一个男人的男人...:)

man man

我忘了谈论帮助,大多数(和体面的)程序都有 -h or/and --help。大多数时候,手册页会显示更多信息。


0
投票

更直接的答案:

 -a    file exists  This is identical in effect to -e. It has been "deprecated," [1] and its use is discouraged.
 -b    file is a block device
 -c    file is a character device  [ -b "/dev/sda2" ]
 -d    file is a directory
 -e    file exists
 -f    file is a regular file (not a directory or device file)
 -G    group-id of file same as yours
 -g    set-group-id (sgid) flag set on file or directory
          If a directory has the sgid flag set, then a file created within that directory belongs to the group
          that owns the directory, not necessarily to the group of the user who created the file.
 -h    file is a symbolic link
 -k    sticky bit1 set
 -L    file is a symbolic link
 -N    file modified since it was last read
 -O    you are owner of file
 -p    file is a pipe  [ -p /dev/fd/0 ]
 -r    file has read permission (for the user running the test)
 -S    file is a socket
 -s    file is not zero size
 -t    file (descriptor) is associated with a terminal device.
 -u    set-user-id2 (suid) flag set on file
 -w    file has write permission (for the user running the test)
 -x    file has execute permission (for the user running the test)

 -nt   file f1 is newer than f2   f1 -nt f2
 -ot   file f1 is older than f2   f1 -ot f2
 -ef   files f1 and f2 are hard links to the same file   f1 -ef f2
    
 !     "not" -- reverses the sense of the tests above (returns true if condition absent).

参考:https://ss64.com/bash/syntax-file-operators.html

© www.soinside.com 2019 - 2024. All rights reserved.