Bash Script: Trouble unable to run


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Script: Trouble unable to run
# 1  
Old 07-20-2009
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  
Old 07-20-2009
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  
Old 07-20-2009
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  
Old 07-20-2009
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  
Old 07-20-2009
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  
Old 07-20-2009
Quote:
Originally Posted by rchirico
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 Smilie


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  
Old 07-20-2009
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 ;;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Unable to run the script on remote machine Using Expect script

Not able to execute the file in remote host using except utility I am automating the SFTP keys setp process: So i created the expect script for controlling the output of shell below is my main code: Code: #!/usr/bin/expect set fd set password close $fd set df set app close $df... (1 Reply)
Discussion started by: Manoj Bajpai
1 Replies

2. Homework & Coursework Questions

Linux/UNIX Bash Shell Script trouble help needed!!

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 2. Shell Bash Script 3. !/bin/bash if echo no directory then mkdir -p /home/AC_Drywall elif ; then echo "$dir already exist" fi (4 Replies)
Discussion started by: TomFord1
4 Replies

3. Shell Programming and Scripting

Having trouble with My Bash Script, need Help debugging

Hello Friends I am having trouble with my script below. I will describe the problems below the code box. I am hoping that some of the experts here can help me. #!/bin/bash #========================================================================================================= # Rsync File... (8 Replies)
Discussion started by: jdavis_33
8 Replies

4. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

5. Shell Programming and Scripting

php file unable to run shell script with arguments

echo $result=exec("./permit.sh".$_FILES); pls suggest some other method to run shell script in php .:wall::mad: (0 Replies)
Discussion started by: upvan111
0 Replies

6. SuSE

Unable to Run a script at startup in suse

Hi I have a script myscript.sh that needs to be run whenever the server boots. The script is actually logging Syslog-ng messages to sql server. I need to lauch it at startup I have copied the script in etc/init.d i have also added the link ln -s /etc/init.d/syslog-ng-mssql-pipe.sh... (5 Replies)
Discussion started by: SystemEng
5 Replies

7. Shell Programming and Scripting

Quoting issue: Trouble with bash strings in script

I can do this on the command line: sqsh -S 192.168.x.x -o tmp -U user -P fakepass -D horizon -C "\ select second_id from borrower where btype like '%wsd%' " I can also just leave the SQL at the end intact on one line .... ... However, when I throw this in a script like: $SQSH -o... (4 Replies)
Discussion started by: Bubnoff
4 Replies

8. Shell Programming and Scripting

unable to run mono app using .sh script

I did a search for this problem but couldn't find any specific answers to my problem. We have a .NET application compiled in SharpDevelop for Mono which we want to execute with a .sh shell script on Ubuntu. When we execute the script nothing happens meaning the application's visual interface... (0 Replies)
Discussion started by: JacquesB
0 Replies

9. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

10. Shell Programming and Scripting

unable to run a script

thi is (10 Replies)
Discussion started by: angelina
10 Replies
Login or Register to Ask a Question