什么`+选项`在bash命令中意味着什么?

时间:2018-06-18 02:42:20

标签: bash getopt

我之前从未见过某种特殊的bash格式 special bash command :foo -a -c +b

 foo -a -c +b

foo是一个bash命令,acfoo个选项。
对于上面的命令,+b在这里意味着什么?

禁用脚本中的选项。

foo命令具有b选项,或者说b命令中存在foo行为,

foo -a -c +b将调用ac行为并禁用b行为。

为什么不运行:

foo -a -c

1 个答案:

答案 0 :(得分:3)

根据Advanced Bash-Scripting Guide,对于bash选项:

  • -option启用默认为已停用的选项
  • +option禁用默认启用的选项

因此,其他程序将采用相同的启用和禁用选项的方法是有意义的。

给出的bash示例是:

  #!/bin/bash

  set -o verbose
  # Command echoing on.
  command
  ...
  command

  set +o verbose
  # Command echoing off.
  command
  # Not echoed.


  set -v
  # Command echoing on.
  command
  ...
  command

  set +v
  # Command echoing off.
  command

  exit 0
相关问题