[英]Shell Script Argument without value
I'm creating a very simple sh file to do something, but I want to pass an argument without a value, for example: 我正在创建一个非常简单的sh文件来执行某些操作,但我想传递一个没有值的参数,例如:
./fuim -l
But I receive the following message: 但我收到以下消息:
./fuim: option requires an argument -- l
If I pass a random value, like ./fuim -l 1
, it works perfectly. 如果我传递一个随机值,比如
./fuim -l 1
,它就可以完美地运行。 How can I do that? 我怎样才能做到这一点?
Here's what I have so far: 这是我到目前为止所拥有的:
while getopts e:f:l:h OPT
do
case "$OPT" in
h) print_help ;;
e) EXT=$OPTARG ;;
f) PROJECT_FOLDER=$OPTARG ;;
l) LIST_FILES=1 ;;
?) print_help ;;
esac
done
shift $((OPTIND-1))
if [ -z "$EXT" ] || [ -z "$PROJECT_FOLDER" ]; then
print_help
fi
When using getopts
, putting :
after an option character means that it requires an argument. 使用
getopts
,put :
在选项字符后表示它需要一个参数。 So change l:
to l
, as in: 所以将
l:
改为l
,如:
while getopts e:f:lh OPT
This makes it a boolean option, either it's there or it isn't. 这使它成为一个布尔选项,无论是存在还是不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.