이것은 내 입력입니다.
#!/bin/bash
#Example of menu programs
clear
echo "*******************"
echo "1.Date"
echo "2.List of users"
echo "3.Open a file"
echo "4.delete a file"
echo "5.Exit"
echo "Enter a choice[1-5] :"
read choice
case $choice in
1) echo "Today date is : `date`";;
2) who ;;
3) `touch file`;;
4) `rm -rf kk`;;
5) exit ;;
*) echo "choice wrong. try again";;
esac
이것은 내 결과입니다.
*******************
1.Date
2.List of users
3.Open a file
4.delete a file
5.Exit
Enter a choice[1-5] :
1
Today date is : Sun Jul 19 08:07:41 PDT 2015
그러나 나는 이 결과를 기대하지 않습니다.
나는 무엇을 기대합니까?
*******************
1.Date
2.List of users
3.Open a file
4.delete a file
5.Exit
Enter a choice[1-5] :
1
Today date is : Sun Jul 19 08:07:41 PDT 2015
*******************
1.Date
2.List of users
3.Open a file
4.delete a file
5.Exit
Enter a choice[1-5] :
이 목표를 어떻게 달성할 수 있나요?
답변1
루프에 넣습니다.
while true; do
echo "*******************"
echo "1.Date"
echo "2.List of users"
echo "3.Open a file"
echo "4.delete a file"
echo "5.Exit"
echo "Enter a choice[1-5] :"
read choice
case $choice in
1) echo "Today date is : `date`";;
2) who ;;
3) `touch file`;;
4) `rm -rf kk`;;
5) break ;;
*) echo "choice wrong. try again";;
esac
done
아니면 스크립트를 루프에 넣으세요
while true; do
menu.sh
done
답변2
#!/bin/bash
#Example of menu programs
while true;
do
echo "*******************"
echo "1.Date"
echo "2.List of users"
echo "3.Open a file"
echo "4.delete a file"
echo "5.Exit"
echo "*******************"
echo "Enter a choice[1-5] :"
read choice
case $choice in
1) echo "Today date is : `date`";;
2) who ;;
3) `touch file`;;
4) `rm -rf kk`;;
5) break ;;
*) echo "Wrong choice. Please try again";;
esac
done
귀하의 정보를 위해:유닉스 - 쉘 루프 제어