これは私の入力です。
#!/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
あなたの情報のために:Unix - シェルループ制御