shell - 以空格分隔的读取 Shell 脚本选项
问题描述
我有这个 shell 脚本:
for i in "$@"
do
case $i in
-l=*|--ddloc=*)
DDLOC="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
它工作正常,-x=y
但我想成为这样-x y
。这里需要进行哪些更改?
解决方案
for i in "$@"
do
case $i in
-l=*|--ddloc=*)
DDLOC="${i#*=}"
shift # past argument=value
;;
-l|--ddloc)
shift # past argument
DDLOC="$1"
shift # past value
;;
*)
# unknown option
;;
esac
done
推荐阅读
- firebase - 如何在Android上将图像字符串转换为整数?
- javascript - 如何使用本地存储?
- git - 对于 Micosoft Dynamics 365,如果存在有效的解决方案/项目 git 存储库,我如何将项目导入我的开发人员环境?
- angular - 如何在使用路由器插座导航到子组件时在父组件中保留表单数据
- binary-tree - 为什么不预先订购递归逻辑?
- xpath - XPath 1.0 IEEE 754 - 最小位数?
- html - 字体字距中断,中间有绝对 div
- command-line-interface - 如何使用 git bash MINGW64 CLI 在 Windows 上的文件浏览器应用程序中打开目录?
- wcag - 如何将文本内容放置在
- java - 找到 PID 文件但未找到匹配的进程或当前用户无权停止进程