onde devo modificar o script de shell fornecido?

1

Esta é minha opinião:

#!/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

Esta é minha saída:

*******************
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

Mas não estou esperando essa saída.

O que estou esperando:

*******************
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] :

Como posso conseguir isso?

    
por Kiran Reddy 19.07.2015 / 16:53

2 respostas

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

Para sua referência: Unix - Shell Loop Control

    
por 19.07.2015 / 18:07
3

Coloque em um loop:

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

ou coloque seu script dentro do loop

while true; do
     menu.sh
done
    
por 19.07.2015 / 17:59