Bash long options getopts

125 Views Asked by At

I wrote a bash script, how can i add a long options for example: --verbose along with -v option?

My second question is what is the difference between while getopts :v and while getopts v, i've done some research and i still can't fully understand it.

I have tried it with getopts but not working, also heard that getopt is not the right choice.

while getopts ":v" option; do
  case $option in
    v) verbose=true;;
    ?) echo "Invalid option: -$OPTARG" >&2 && exit 1;;
  esac
done
0

There are 0 best solutions below