The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-20-2009
rchirico rchirico is offline
Registered User
  
 

Join Date: Jul 2009
Location: PA
Posts: 6
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!
  #2 (permalink)  
Old 07-20-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
  #3 (permalink)  
Old 07-20-2009
BubbaJoe's Avatar
BubbaJoe BubbaJoe is offline
Registered User
  
 

Join Date: Oct 2008
Location: St Louis
Posts: 153
Check your parenthesis.


Code:
       6) echo "Files in `pwd` ; ls -l ; echo "Press any key ..." ; read ;;

Should read


Code:
       6) echo "Files in `pwd`" ; ls -l ; echo "Press any key ..." ; read ;;

  #4 (permalink)  
Old 07-20-2009
RiSk RiSk is offline
Registered User
  
 

Join Date: May 2008
Posts: 20
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.
  #5 (permalink)  
Old 07-20-2009
rchirico rchirico is offline
Registered User
  
 

Join Date: Jul 2009
Location: PA
Posts: 6
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
  #6 (permalink)  
Old 07-20-2009
RiSk RiSk is offline
Registered User
  
 

Join Date: May 2008
Posts: 20
Quote:
Originally Posted by rchirico View Post
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

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

  #7 (permalink)  
Old 07-20-2009
BubbaJoe's Avatar
BubbaJoe BubbaJoe is offline
Registered User
  
 

Join Date: Oct 2008
Location: St Louis
Posts: 153
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 ;;

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0