I'm trying to create a bash script that lets the user use both a menu style and also a command line switch style interface. I was wondering if there was a way to pass a parameter to a menu option in select as if it were just an argument to a script. For example, in my script I can specify a file to move to my junk folder by saying junk -d file.txt. But if the user does not specify any params it should use the select option. i.e. 1) move file 2) clear junk folder 3) watch folder etc.
On this menu, I want to be able to write the option and then send an argument to that option. Like 1 filetobemoved.txt. I have tried putting $OPTARG after the method that gets called by the menu but this doesn't seem to work.
Here is the code I have for the menu at the moment, I'm trying to call the recover method and pass an argument (the filename) to it.
if (( $# == 0 ))
then if (( $OPTIND == 1 ))
then select menu_list in list recover delete total watch kill exit
do case $menu_list in
"list") list;;
"recover") recover $GETOPT;;
"delete") delete;;
"total") total;;
"watch") _watch;;
"kill") _kill;;
"exit") exit 0;;
*) echo "unknown option";;
esac
done
fi
Thanks for any help.