如何使用 getopt 在 UNIX 中创建多字符参数? [英] How to make a multi-character parameter in UNIX using getopt?

查看:21
本文介绍了如何使用 getopt 在 UNIX 中创建多字符参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 getopt 命令,以便当我将-ab"参数传递给脚本时,该脚本会将 -ab 视为单个参数.

I'm trying to make a getopt command such that when I pass the "-ab" parameter to a script, that script will treat -ab as a single parameter.

#!/bin/sh
args=`getopt "ab":fc:d $*`
set -- $args
for i in $args
do
case "$i" in
        -ab) shift;echo "You typed ab $1.";shift;;
        -c) shift;echo "You typed a c $1";shift;;
esac
done

然而,这似乎不起作用.任何人都可以提供任何帮助吗?

However, this does not seem to work. Can anyone offer any assistance?

推荐答案

getopt 不支持您要查找的内容.您可以使用单字母 (-a) 或长选项 (--long).类似-ab 的处理方式与-a b 相同:作为带有参数b 的选项a.请注意,长选项前面有两个破折号.

getopt doesn't support what you are looking for. You can either use single-letter (-a) or long options (--long). Something like -ab is treated the same way as -a b: as option a with argument b. Note that long options are prefixed by two dashes.

这篇关于如何使用 getopt 在 UNIX 中创建多字符参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆