Linuxでメニューを作る作業を任せたのですが、効果が悪くはないようです。何かを選択した場合は、そのタスクを実行し、タスクが完了したらメインメニューに戻りたいと思います。
#!/bin/bash
PS3='What do you want to do day: '
options=("Create Group" "Delete Group" "Create User 3" "Delete User" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Create Group")
echo "You chose Create Group 1"
;;
"Delete Group")
echo "You chose to Delete Group"
;;
"Create User")
echo "You chose to Create User"
;;
"Delete User")
echo "You choose to Delete User"
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done
答え1
whileと永続的なtrue条件を使用してこれを実行できます。
while [ 1 -eq 1 ] # or while [ true ] ( as glenn said)
do
select opt in "${options[@]}"
do
case $opt in
"Create Group")
echo "You chose Create Group 1"
;;
"Delete Group")
echo "You chose to Delete Group"
;;
"Create User")
echo "You chose to Create User"
;;
"Delete User")
echo "You choose to Delete User"
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done
done
答え2
毎回メニューを見せたいと思います。この試み:
quit=false
until $quit; do
select opt in "${options[@]}"; do
case $opt in
"Create Group")
echo "You chose Create Group 1"
break
;;
"Delete Group")
echo "You chose to Delete Group"
break
;;
"Create User")
echo "You chose to Create User"
break
;;
"Delete User")
echo "You choose to Delete User"
break
;;
"Quit")
quit=true
break
;;
*) echo invalid option;;
esac
done
done