![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trouble with tee command to capture script outputs | muthubharadwaj | Shell Programming and Scripting | 5 | 02-16-2009 08:29 PM |
| how to make your bash script run on a machine with csh and bash | npatwardhan | Shell Programming and Scripting | 3 | 11-19-2008 04:17 AM |
| passing variable from bash to perl from bash script | arsidh | Shell Programming and Scripting | 10 | 06-04-2008 01:25 PM |
| trouble in running script | cahyo3074 | Shell Programming and Scripting | 2 | 05-21-2008 01:22 AM |
| trouble with script | whegra | Shell Programming and Scripting | 4 | 10-17-2002 02:48 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Bash Script: Trouble unable to run
I am trying to create a menu, and the script fails on ln 38 (Files in pwd). Any idea on where the problem is?? Thanks for the help Rob Code:
#!/bin/bash
# Cool Script for Weekly Assignment 2 (#3) that creates a menu to act as a ui
# and run some popular commands.
clear
while :
do
clear
echo "**************************************************"
echo " Main Menu of Linux User Interface"
echo " Today's Date and Time: " `date`
echo "**************************************************"
echo "[1] Display Calendar for current year"
echo "[2] Show files in your home directory"
echo "[3] Launch vi to create/edit a file"
echo "[4] Shutdown system now"
echo "[5] Shutdown system in 5 minutes"
echo "[6] Show files in current directory"
echo "[7] Exit/Stop"
echo "******************************"
echo -n "Please enter your menu choice [1-7] : "
read choice
case $choice in
1) echo `cal -y`; echo "Press any key ..."; read ;;
2) echo "Files in `$HOME`" ; ls -l ; echo "Press any key ..." ; read ;;
3) vi ;;
4) clear
echo " "
echo " "
read -p "Are you sure you want to shut down? - Y/N: " choice
if [[ "$choice" = 'Y' ]] ; then
sudo shutdown -h now
fi
clear ;;
5) sudo shutdown -h now
6) echo "Files in `pwd` ; ls -l ; echo "Press any key ..." ; read ;;
7) exit 0 ;;
*) echo "Invalid selection!!! Please select choice 1,2,3,4,5,6, or 7";
echo "Press any key ..." ; read ;;
esac
done
Last edited by vgersh99; 07-20-2009 at 06:29 PM.. Reason: code tags, PLEASE! |
|
||||
|
Here ya go; Code:
#!/bin/bash
# Cool Script for Weekly Assignment 2 (#3) that creates a menu to act as a ui
# and run some popular commands.
clear
while :
do
clear
echo "**************************************************"
echo " Main Menu of Linux User Interface"
echo " Today's Date and Time: " `date`
echo "**************************************************"
echo "[1] Display Calendar for current year"
echo "[2] Show files in your home directory"
echo "[3] Launch vi to create/edit a file"
echo "[4] Shutdown system now"
echo "[5] Shutdown system in 5 minutes"
echo "[6] Show files in current directory"
echo "[7] Exit/Stop"
echo "******************************"
echo -n "Please enter your menu choice [1-7] : "
read choice
case $choice in
1) echo `cal -y`; echo "Press any key ..."; read ;;
2) echo "Files in `$HOME`" ; ls -l ; echo "Press any key ..." ; read ;;
3) vi ;;
4) clear
echo " "
echo " "
read -p "Are you sure you want to shut down? - Y/N: " choice
if [[ "$choice" = 'Y' ]] ; then
sudo shutdown -h now
fi
clear ;;
5) sudo shutdown -h now ;;
6) echo "Files in `pwd`"; ls -l ; echo "Press any key ..."; exit ;;
7) exit 0 ;;
*) echo "Invalid selection!!! Please select choice 1,2,3,4,5,6, or 7";
echo "Press any key ..." ; read ;;
esac
done
Couple of issues, be aware of you're simi colons; you did not have any on the end of #5, alos you need to finish out your quotes on 6. but just as an FYI; when you press 6, its going to echo it and then move on, you will never see it, so I added an exit so you would see it. |
|
||||
|
Joe,
Thanks for your help. I still can't get it to work. Funny thing though, when I comment out options 6 & 7, it works. I tried deleting the line, and re-typing it to no avail. Something about the parenthesis 6) is giving me an error. That parenthesis appears as a different color other than options 1-5. Thanks, Rob |
|
||||
|
Quote:
rchirico, its because you did not close off number 5 with a ;;, copy and paste mine and try it. I know it works ![]() Code:
risk@Heavyarms [238] --> cat ./test.sh
#!/bin/bash
# Cool Script for Weekly Assignment 2 (#3) that creates a menu to act as a ui
# and run some popular commands.
clear
while :
do
clear
echo "**************************************************"
echo " Main Menu of Linux User Interface"
echo " Today's Date and Time: " `date`
echo "**************************************************"
echo "[1] Display Calendar for current year"
echo "[2] Show files in your home directory"
echo "[3] Launch vi to create/edit a file"
echo "[4] Shutdown system now"
echo "[5] Shutdown system in 5 minutes"
echo "[6] Show files in current directory"
echo "[7] Exit/Stop"
echo "******************************"
echo -n "Please enter your menu choice [1-7] : "
read choice
case $choice in
1) echo `cal -y`; echo "Press any key ..."; read ;;
2) echo "Files in `$HOME`" ; ls -l ; echo "Press any key ..." ; read ;;
3) vi ;;
4) clear
echo " "
echo " "
read -p "Are you sure you want to shut down? - Y/N: " choice
if [[ "$choice" = 'Y' ]] ; then
sudo shutdown -h now
fi
clear ;;
5) sudo shutdown -h now ;;
6) echo "Files in `pwd`"; ls -l ; echo "Press any key ..."; exit ;;
7) exit 0 ;;
*) echo "Invalid selection!!! Please select choice 1,2,3,4,5,6, or 7";
echo "Press any key ..." ; read ;;
esac
done
-(~/fun/unixforums)--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------(16:46 Mon Jul 20)
risk@Heavyarms [239] --> sh ./test.sh
**************************************************
Main Menu of Linux User Interface
Today's Date and Time: Mon Jul 20 16:46:15 CDT 2009
**************************************************
[1] Display Calendar for current year
[2] Show files in your home directory
[3] Launch vi to create/edit a file
[4] Shutdown system now
[5] Shutdown system in 5 minutes
[6] Show files in current directory
[7] Exit/Stop
******************************
Please enter your menu choice [1-7] : ^C
-(~/fun/unixforums)--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------(16:46 Mon Jul 20)
risk@Heavyarms [240] -->
|
|
|||||
|
Can you repost your lines 5, 6, and 7 so we can look at what you have now. Also there should be a read and not an exit in code Code:
6) echo "Files in `pwd`"; ls -l ; echo "Press any key ..."; exit ;; should be Code:
6) echo "Files in `pwd`"; ls -l ; echo "Press any key ..."; read ;; |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|