LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2007, 06:52 PM   #1
cashton2k
Member
 
Registered: May 2004
Posts: 46

Rep: Reputation: 15
newbie bash programmer question


hi i'm tryin to make a simple script with bash but i keep gettin an error when i try and run the script on the line "Q|q) quit=yy;;"

I was wonderin if anyone cud help, it must be sumthin silly im missin

thanks for any help

Last edited by cashton2k; 03-05-2007 at 02:21 PM.
 
Old 03-04-2007, 07:05 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
The line with "done" before "Q|q) ..." should be "done ;;"
 
Old 03-04-2007, 08:58 PM   #3
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by cashton2k
hi i'm tryin to make a simple script with bash but i keep gettin an error when i try and run the script on the line "Q|q) quit=yy;;"

Code:
#!/bin/sh
#Filename: secondarynode
quit=n

location=$(echo $(pwd))
You don't need echo or any command substitution; if you need to store the output of pwd, you should use:

location=$(pwd)

However, you don't even need that, as the current directory is stored in $PWD:

location=$PWD

Quote:
Code:
while [  "$quit"   =   "n"  ];
do
  clear
  echo "Secondary Node Control Utility"
  echo
  echo
  echo "1. Activate Heartbeat and Failover System"
  echo "Q. Quit"
  echo
  echo "Enter choice:"
  read choice
  case $choice in
  1)  while [ "$BEAT" -eq 0 ];
      do
      dump=`ping -c 1 192.168.225.120`
      if [ ! $? == 0 ];
      then
      echo "WARNING: Primary Node is Dead"
      let BEAT=BEAT+1
I recommend using the portable, POSIX syntax for shell arithmetic:

BEAT=$(( $BEAT + 1 ))

Quote:
Code:
      else
      echo "Primary Node is Alive at:"
      fi
      done
You are missing the closing ';;' before the next case.

Quote:
Code:
  Q|q) quit=y;;
  *) echo "Invalid Selection!"
      sleep 1
   esac
done
echo "Program Closed"
I was wonderin if anyone cud help, it must be sumthin silly im missin

thanks for any help
 
Old 03-05-2007, 05:48 AM   #4
cashton2k
Member
 
Registered: May 2004
Posts: 46

Original Poster
Rep: Reputation: 15
cheers, thanks guys i got it going great
 
Old 03-05-2007, 01:48 PM   #5
cashton2k
Member
 
Registered: May 2004
Posts: 46

Original Poster
Rep: Reputation: 15
hey sorry bother folk again but im tryin to make a bigger menu system on another similar script is it possible to have a case with a another, my attempts so far have failed

Code:
#!/bin/sh
#Filename: nascontrol
quit=n

location=$(echo $(pwd))

while [  "$quit"   =   "n"  ]
do
  clear
  echo "Network Attached Storage Control Utility"
  echo
  echo "Your current location is: " $location
  echo
  echo "1. NFS Mount Space"
  echo "2. NFS Unount Space"
  echo "3. Check NFS Service Status"
  echo "4. Start NFS Service"
  echo "5. View Currently Exported Areas"
  echo "6. View Available Directories"
  echo "Q. Quit"
  echo
  echo "Enter choice:"
  read choice
  case $choice in
  1) echo "Please enter the directory you would like to export:"
     echo
     echo "Would you like include the current working directory?"
      read pwdquest
      case $pwdquest in
      Y|y) echo "Enter Directory under: $location"
           read sharedir
           echo
           exportfs -v  :$location/$sharedir
           echo "Directory has been Exported"
           echo
           echo "Hit Enter..."
                read junk;;
      N|n) echo "Enter full path of directory"
           read shareddir
           echo
           exportfs -v  :$sharedir
           echo "Directory has been Exported"
           echo
           echo "Hit Enter..."
                read junk;;
      *)    echo "Invalid choice!"
            sleep 1
         esac 
     done ;;
  2) echo "Please enter the directory you would like to unexport"
      read unsharedir
      exportfs -u :$unsharedir
      echo "Directory is no longer being exported"
      echo
      echo "Hit Enter..."
      read junk;;
  3)  service nfs status
      echo "Hit Enter..."
      read junk;;
  4)  service nfs start
      echo "Hit Enter..."
      read junk;;
  5)  showmount -e
      echo
      echo "Hit Enter..."
      read junk;;
  6)  dir
      echo
      echo "Hit Enter..."
      read junk;;
  Q|q) quit=y;;
   *) echo "Invalid choice!\07\07"
      sleep 1
   esac
done
echo "Program Exit Completed"
i get errors for the done on the second case

Last edited by cashton2k; 03-05-2007 at 01:49 PM.
 
Old 03-05-2007, 02:25 PM   #6
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
..............

Last edited by ygloo; 03-05-2007 at 02:27 PM.
 
Old 03-05-2007, 02:25 PM   #7
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
You are missing the closing ';;'

Code:
      *)    echo "Invalid choice!"
            sleep 1
         esac

       *) echo "Invalid choice!\07\07"
             sleep 1
       esac

Last edited by ygloo; 03-05-2007 at 02:35 PM.
 
Old 03-05-2007, 02:32 PM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
There was one "do" but two "done" in your script ...

Edited: Ygloo, please add some comments to your postings. An empty post or one with only code doesn't help figuring out where you are now with your script.

Thanks.

Last edited by jlliagre; 03-05-2007 at 02:36 PM.
 
Old 03-05-2007, 02:47 PM   #9
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
you could add ";;" on a new line to make reading easier:
Code:
Y|y) echo "Enter Directory under: $location"
           read sharedir
           echo
           exportfs -v  :$location/$sharedir
           echo "Directory has been Exported"
           echo
           echo "Hit Enter..."
                read junk
           ;;

Last edited by ygloo; 03-05-2007 at 02:48 PM.
 
Old 03-05-2007, 03:09 PM   #10
cashton2k
Member
 
Registered: May 2004
Posts: 46

Original Poster
Rep: Reputation: 15
cheers again guys really appreciate it
 
Old 03-05-2007, 03:51 PM   #11
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by cashton2k
hey sorry bother folk again but im tryin to make a bigger menu system on another similar script is it possible to have a case with a another, my attempts so far have failed

Code:
#!/bin/sh
#Filename: nascontrol
quit=n

location=$(echo $(pwd))
location=$PWD

Note the difference:

Code:
$ time location=$PWD

real    0m0.000s
user    0m0.000s
sys     0m0.000s
$ time location=$( echo $(pwd))

real    0m0.010s
user    0m0.001s
sys     0m0.008s
Quote:
Code:
while [  "$quit"   =   "n"  ]
do
  clear
  echo "Network Attached Storage Control Utility"
  echo
  echo "Your current location is: " $location
  echo
  echo "1. NFS Mount Space"
  echo "2. NFS Unount Space"
  echo "3. Check NFS Service Status"
  echo "4. Start NFS Service"
  echo "5. View Currently Exported Areas"
  echo "6. View Available Directories"
  echo "Q. Quit"
  echo
  echo "Enter choice:"
  read choice
  case $choice in
  1) echo "Please enter the directory you would like to export:"
     echo
     echo "Would you like include the current working directory?"
      read pwdquest
      case $pwdquest in
      Y|y) echo "Enter Directory under: $location"
           read sharedir
           echo
           exportfs -v  :$location/$sharedir
           echo "Directory has been Exported"
           echo
           echo "Hit Enter..."
                read junk;;
      N|n) echo "Enter full path of directory"
           read shareddir
           echo
           exportfs -v  :$sharedir
           echo "Directory has been Exported"
           echo
           echo "Hit Enter..."
                read junk;;
      *)    echo "Invalid choice!"
            sleep 1
         esac 
     done ;;
i get errors for the done on the second case
What loop does that "done" close?
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie bash question about a secondhand script madtinkerer Programming 22 11-27-2006 08:02 AM
Newbie Bash Scripting Question jsaxton86 Programming 2 11-26-2005 07:58 PM
newbie Linux programmer uglyugly Programming 4 06-08-2004 08:46 AM
Newbie Bash scripting question Caidence Programming 2 08-03-2003 04:53 AM
Newbie bash scripting question... cmfarley19 Linux - Newbie 2 05-03-2003 08:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration