I'm creating a very simple sh file to do something, but I want to pass an argument without a value, for example:
./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. 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. So change l:
to l
, as in:
while getopts e:f:lh OPT
This makes it a boolean option, either it's there or it isn't.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.