bash - 有没有办法限制 getopts 只能在单个选项上工作?
问题描述
我正在用 getopts 编写一个包含多个 case 语句的 bash 脚本。我的要求是能够决定什么时候 getopts 可以采取多种选择,什么时候不可以。
while getopts "hla:d:t:k:w:e:f:i:m:u:L:D:" options
do
case $options in
h)
if [[ "${OPTARG}" = -* ]]; then
echo "Multiple options are not allowed"
exit 1
fi
verboseHelpAndExit
break
;;
l)
if [[ "${OPTARG}" = -* ]]; then
echo "Multiple options are not allowed"
exit 1
fi
if [ "$#" -gt 0 ] || [ "$1" != '-l' ]; then
echo "No parameters allowed"
else
list_users
fi
break
;;
w)
warn="$OPTARG"
check_for_integer $warn
;;
e)
expire="$OPTARG"
check_for_integer $expire
;;
这里 -h 和 -l 不应采用任何其他选项,如果通过任何其他选项,则应给出错误,但 -w 和 -e 可以采用多个选项,我的代码块有什么问题?
解决方案
推荐阅读
- caching - 如何在 Laravel 7 中查看缓存记录?
- postgresql - 我想在 idP 的帮助下实施 SCIM
- .htaccess - 如何修复本地主机上的 .htaccess mod_rewrite 服务器错误
- html - Bootstrap 组件的角度问题
- r - install.packages 中的错误:没有适用于“过滤器”的方法应用于“字符”类的对象
- html - 如何接口启动函数,停止函数以启动无限期循环并使用烧瓶停止它?
- c# - 在不删除 ML.NET 中的列的情况下设置训练管道
- java - BigQuery TableResult 转换选项
- python - 有没有办法让 if 语句知道我的输入是一个数字?
- pandas - 列的划分没有返回正确的值