0

I have a basic menu that completes tasks that have already been set to me, i have the menu to show up and the functions to work, however, when the user chooses option 4, the results only blink in the terminal for a split second, and also if they choose an incorrect value, the error message blinks, i need both of them to stay put. Any ideas?

#!/bin/bash
#
# Script to perform some simple tasks
#
chmod 755 TaskB.sh
while:
do
clear
echo "*********************"
echo "* Tools *"
echo "*********************"
echo "* [1] Install gnome-disk-utility and gparted *"
echo "* [2] Create CET103Demo.txt *"
echo "* [3] Delete CET103Demo.txt *"
echo "* [4] Search BASH *"
echo "* [0] Exit/Stop *"
echo "*********************"
echo -n "Enter your menu choice [0-4]: "
read yourch
case $yourch in
1) sudo apt-get install gparted gnome-disk-utility ;;
2) cat > Desktop/CET103Demo.txt;;
3) rm Desktop/CET103Demo.txt;;
4) grep -H -r "BASH" /home/mintuser/.profile ;;
0) exit 0;;
*) echo "Oooops!!! Please select choice 1,2,3,4 or 0";
echo "Press Enter to continue..."; read ;;
esac
done
Cain Neal
  • 197
  • 2
  • 4
  • 15

1 Answers1

0

I haven't used bash in a while but try this:

#!/bin/bash
#
# Script to perform some simple tasks
#
chmod 755 TaskB.sh
while:
do
clear
echo "*********************"
echo "* Tools *"
echo "*********************"
echo "* [1] Install gnome-disk-utility and gparted *"
echo "* [2] Create CET103Demo.txt *"
echo "* [3] Delete CET103Demo.txt *"
echo "* [4] Search BASH *"
echo "* [0] Exit/Stop *"
echo "*********************"
echo -n "Enter your menu choice [0-4]: "
read yourch
case $yourch in
1) sudo apt-get install gparted gnome-disk-utility ;;
2) cat > Desktop/CET103Demo.txt;;
3) rm Desktop/CET103Demo.txt;;
4) grep -H -r "BASH" /home/mintuser/.profile ;;
0) exit 0;;
*) echo "Oooops!!! Please select choice 1,2,3,4 or 0" ;;
esac
read -p "Press [Enter] to continue..."
done
read -p "Press [Enter] to exit..."
Nathan Goings
  • 1,145
  • 1
  • 15
  • 33
  • unfortunatly not, i also tried to replace your given code with my read statement – Cain Neal Mar 19 '13 at 21:44
  • still no luck by moving the statement – Cain Neal Mar 19 '13 at 21:48
  • I'm not sure I quite understand your problem. When you indicate "blink", I consider that to mean the script exits. On Windows or Mac the same problem happens when the command prompt or terminal finishes executing. I'll update my answer to include your entire code with my changes. – Nathan Goings Mar 19 '13 at 22:02
  • when the user presses a number that is not 0-4 the oooops message should diplay, but i plinks for a fraction of a second, i need it to stay put and wait for a key entry to dissapear – Cain Neal Mar 19 '13 at 22:07
  • Well, I edited it. The first read should allow you to see output from option 4 and the second read will allow you to see the error message. – Nathan Goings Mar 19 '13 at 22:08
  • thanks for the help Nathan, but the error still occurs, not sure there is a fix :S – Cain Neal Mar 19 '13 at 22:19