So I am trying to make a little custom management script for my server, but I am running into a problem for creating my menu script with the right results.
I got the following script
function config
{
list=''
declare -a programs=("docker" "IdontExist" "pushover" "IdontexistEither")
for program in "${programs[@]}"
do
#Check if command exists on the server
if hash $program 2>/dev/null; then
list="${list} "${program}""
fi
done
title="Config manager"
prompt="Pick an option:"
options=(${list})
echo "$title"
PS3="$prompt "
select opt in "${options[@]}" "Quit"; do
case "$REPLY" in
#Dont know how to create this section in a script
1 ) echo "Update Docker"; break;;
3 ) echo "Update IdontExist"; break;;
2 ) echo "Update mytest"; break;;
4 ) echo "Update IdontExistEither"; break;;
$(( ${#options[@]}+1 )) ) echo "Goodbye!"; break;;
*) echo "Invalid option. Try another one.";continue;;
esac
done
}
My list variable will look as follow
list: "docker" "pushover"
So my options in the script above will not work accordingly. How can I create the options, depending on the list variable?
And I also want to call in certain functions depending on the selected option, for example if somebody choose "docker" I want to call a function named: _docker_config and when its "pushover" I will call a function named _pushover_config How would I also achieve that in the script?
See Question&Answers more detail:os