linux - 巴什 : Difference between '-' and '--' options

标签 linux bash shell sh ls

我正在学习 Shell (Bash) 脚本编写 的入门书,并且有以下疑问:

  • I came across the ls command

  • The man page of ls lists a few use cases as :

    ls -a
    ls --block-size='M'

我的问题:

  • What is the difference in - and -- ?
  • Why are there 2 nomenclatures used ?
  • What is the motivation behind it ?

最佳答案

长格式 (--foo) 选项是 GNU 扩展 -- GNU ls 中存在的东西,但根本不存在于 POSIX 标准设置要求中UNIX 工具,因此其他版本的 ls 没有义务支持这些选项。在这种情况下,整个单词 (foo) 是有意义的。这个命名法是最近添加的,比缩写形式更具表现力(并且没有命名空间限制)。

短格式选项 (-al) 至少在形式上是标准化的(尽管扩展可以添加新的)。它们是逐个字符处理的,一次一个字母——所以 -al 表示 -a(显示隐藏文件)和 -l (长输出),而不是让 -al 在这种情况下有自己的含义。这是 UNIX 命令行选项的原始语法,因此不仅为了简洁而且为了向后兼容而受到支持。

关于linux - 巴什 : Difference between '-' and '--' options,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28279812/

相关文章:

linux - 在多台机器上的oracle JDK上执行tzupdater工具

linux - 在 Linux 中推送到私有(private) git 存储库的问题

linux - 在 bash 中读取一行文件

Linux shell - 如果文件已被删除,如何查找所有正在运行的进程

linux - 如果程序由 linux 命令屏幕启动,如何使程序从文件接收 "standard"输入?

c++ - 在linux下运行补丁时出现问题

c - Xenomai 中的周期性线程实时失败

windows - 将终端区域设置永久设置为 C.UTF8

shell - SED 用单引号和双引号替换内容

perl - 日志文件两行之间的时间差