linux - shell 脚本 : how to use getopts to get last arguments and unhandle arguments

标签 linux bash shell archlinux

有一个名为cower 的程序. (cower 是一个 Archlinux AUR 下载器。)

cower -[udhsc] target

我正在编写一个名为 xcower 的 shell 脚本.

xcower -[Syudhsc] target1 target2 target3 ...

xcower取 2 个附加参数 S 和 y。并将剩余的参数传递给 cower。我不知道如何获得剩余参数和目标。

顺便说一句,xcower目标是在 1 个命令中从全新安装的 Arch 安装 AUR 包。

最佳答案

您可以尝试使用 shiftOPTIND 变量的组合,例如(不回答)

shift $(($OPTIND - 1))

来自 bash 引用

OPTIND The index of the next argument to be processed by the getopts builtin command (see SHELL BUILTIN COMMANDS below).

shift [n] The positional parameters from n+1 ... are renamed to $1 .... Parameters represented by the numbers $# down to $#-n+1 are unset

关于linux - shell 脚本 : how to use getopts to get last arguments and unhandle arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5602862/

相关文章:

linux - AWS 弹性 beanstalk ec2 服务器上的 node.js 命令

Python bash 输出到字符串

C++ 无法链接 Boost 库

linux - 计算文件夹中所有文件的总行数

linux - 向所有使用 Wall 的人广播用户消息

shell - vim:运行 shell(不是 make,不是 perl,不是...),解析输出,跳转到错误位置

linux - 用于检查最新 ZFS 快照的 Shell 脚本

linux - 运行 bash 脚本,在启动时自动打开终端

linux - 丢失的 TCP 数据包在哪里?

c - AF_XDP : `BPF_MAP_TYPE_XSKMAP` only has entries with `Operation not supported`