I wrote a bash script to help me with the build process of couple web apps. There are different build modes so i tried implementing this using flags (getopts)
dev=false; clean_dest=false; all=false; while getopts c:clean-dest:a:all:d:dev:t:target: flags do case "${flags}" in d) dev=true;; dev) dev=true;; c) clean_dest=true;; clean-dest) clean_dest=true;; a) all=true;; all) all=true;; t) target=${OPTARG};; target) target=${OPTARG};; esac done
If I call it with -d -t "someTarget" it works but when I call it with -c -a -d -t "someTarget" it doesn't take into account '-c' and '-a'.
If I swap around the order of arguments in the while
another flag combinations breaks.
What am I doing wrong?
I am thankful in advance.
CodePudding user response:
Solved by adhering to getopts
's syntax; I had to change the while
line to
while getopts cadt: flags
.