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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With