I am struggling to make a script have this behavior:
- I want to pass options like this
./script -abis the same as./script -a -b - And have this logic: "a & b -> c", "a & c -> c", "b & c -> c" (single option is function as normal)
- Also I want this script to fall back to a function (e.g help function) when calling the script without any option
This is some example:
#!/usr/bin/env bash
if [[ ${#} -eq 0 ]]; then
echo "Default function"
else
while getopts ":a:b:c:" opt; do
case ${opt} in
a) echo "a" ;;
b) echo "b" ;;
c) echo "c" ;;
*) echo -e "Invalid option: ${@}" ;;
esac
done
fi
Any help is appreciated
a:instead ofa), but in your examples you're not passing arguments. This is probably the source of most of your problems.