I am currently trying to make a utility script that has an optional UI. To do it the way I have planned, I would have to launch functions within functions, up to 3 layers deep, without ever returning from those functions. This has left me wondering if it's a bad idea to do so.
Here is a simplified version of what I want to do:
ui () {
#interactive UI stuff would go here, this is just a sample output
ob="-b foo "
oa=""
or="-a bar "
main $ob$oa$or
}
main () {
while getopts ":b:a:r:u" opt ;do
case $opt in
b) ;; #main
a) ;; #script
r) ;; #stuff
u) ui ;; #starts the UI function
esac
done
shift $((OPTIND-1))
#other main script stuff
exit
}
main $@
As you can hopefully see, the script will start the main function with all the positional parameters, if the main function finds the -u option, it'll start the ui function, which does some UI magic to get user input. That input is then started with the main script.
Sorry if there are some mistakes in the script, but I hope it gets the point across.