【发布时间】:2021-09-06 18:20:57
【问题描述】:
有没有办法添加只能用作-p 或-p=value 而不能用作-p value 的参数
我想在脚本中添加一个可选参数--parallel/-p。这是我希望用户传递它的方式:
./script arg1 arg2 -p # this defaults to 10
./script arg1 arg2 -p=13 # This is fine and will set the value to 13
./script arg1 arg2 -p 13 # This is NOT fine and I want to ban this. Next line will tell why.
./script -p arg1 arg2 # I want -p to be usable regardless of its position.
# But here arg1 will be considered as an argument of -p option, which is unwanted.
【问题讨论】: