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.
getoptsis parsing the arguments to thereadArgsfunction, and you’re not giving that function any arguments.Try with: