You currently have no loops, not even of any kind.
Your script runs, waits for you at the choose command, and then drops out at the end.
The illusion of a loop is created by the recursive call to asadmin again, which also waits for you at the choose command and then, itself, drops out at the end.
My first suggestion would be to add an "exit" option into the script and then add a while loop to keep going round and round, asking for something do, until you select that "exit" option.
echo "This is a console"
while [ 1 ]
do
echo "Choice:"
read answer
case answer in
1 )
. . .
2 )
. . .
x )
exit
;;
esac
done
My second suggestion (and they way I've done it in the past) would be to separate the actions from the "menu" script completely. Read the options from a [menu] file and simply change the name of the file you're reading from to "move" between menus.
For example, using these "menu" files:
[main.menu]
1:List Domains:asadmin list-domains
2:Start Domain:@start
3:Stop Domain:@stop
x:Exit:EXIT
[start.menu]
1:Domain 1:asdamin start-domain Domain1
2:Domain 2:asdamin start-domain Domain2
x:Return:@main
[stop.menu]
1:Domain 1:asdamin stop-domain Domain1
2:Domain 2:asdamin stop-domain Domain2
x:Return:@main
You could create a script something like this:
[asmenu.bash]
$! /bin/bash
$MENU_FILE="${1:-main}.menu"
while [ 1 ]
do
echo "${MENU_FILE}"
echo " "
# Print Menu items - Choice number and description
awk -F':' '{print $1, $2}' "${MENU_FILE}"
echo " "
echo "Choice:"
read CHOICE
# Extract the third element (command or menu name)
ACTION=$( awk -F':' '/^'${CHOICE}':/' {print $3}' "${MENU_FILE}" )
if [ "EXIT" = "${ACTION}" ] ; then
exit ' End the menu Script
fi
if [ "${ACTION}" =~ ^@ ] ; then
# Leading at symbol implies a menu name
MENU_FILE="${ACTION:1}.menu"
else
# Otherwise it's a command to execute
${ACTION}
fi
done
Which (if I've written it correctly) should do something like this to, say, start your second Domain:
/* Start of run */
main.menu
1 List Domains
2 Start Domain
3 Stop Domain
x Exit
Choice: 2
start.menu
1 Domain 1
2 Domain 2
x Return
Choice: 2
/* execution of asadmin start-domain Domain2 */
start.menu
1 Domain 1
2 Domain 2
x Return
Choice: x
main.menu
1 List Domains
2 Start Domain
3 Stop Domain
x Exit
Choice: x
/* end of run */