Why 'getopts' within a function fails to work?
bash, ubuntu
Solution
`getopts` is parsing the arguments to the `readArgs` function, and you're not giving that function any arguments.
Try with:
readArgs "$@"
Problem
``` function readArgs() { while getopts "i:o:p:s:l:m" OPTION; do case "$OPTION" in i) input="$OPTARG" ;; o) output="$OPTARG" ;; ... esac done } readArgs if [[ -z "$input" ]]; then echo "Not set!" fi ``` This is always giving me `Not set!` but if I comment out the lines `function readArgs() {`, `}` and `readArgs`, it works. Why? Also, ``` input="$OPTARG" echo "$input" ;; ``` does not work.