My code:
#options() {
while getopts s:v:h opt; do
case ${opt} in
s)
echo -s passed with ${OPTARG}
;;
v)
echo -v passed with ${OPTARG}
;;
h)
usage
exit
;;
*)
usage
exit
;;
esac
done
#}
#options
If I call it in a script everything works as expected. But as soon as I remove the hashes and make a function of the code I never get into the case marks.
Can someone explain this behavior?
EDIT:
The following is my latest insight.
There are 3 possible scopes for variables inside shell scripts:
- local
- global
- "in-main-visible-only" or whatever the exact name is for that scope.