LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-16-2007, 01:36 PM   #1
projektdotnet
LQ Newbie
 
Registered: Aug 2005
Location: Utah
Distribution: Ubuntu 7.04
Posts: 7

Rep: Reputation: 0
Why am I getting an unexpected token error in this script?


When executing the following script I get an error
Code:
./checkstats.sh: line 48: syntax error near unexpected token `else'
./checkstats.sh: line 48: `    else'
Here's the script
Code:
#!/bin/bash -x

# Date is equal to today's session
date=./sessions/`date +%m%d%y`.dat

# Menu
fncMenu()
{
echo "What date do you want to check?"
echo "1. Today"
echo "2. Other"
echo "3. Exit"
}
fncMenu

while :
do
read selection
case $selection in
    1)
    if [ -f $date ]
        echo "File OK" 
        exec 3< $date
        read <&3 myline
        varVM=$myline
        read <&3 myline
        varCB=$myline
        read <&3 myline
        varHS=$myline
        read <&3 myline
        varOT=$myline
        read <&3 myline
        varNO=$myline
        read <&3 myline
        varPS=$myline
        read <&3 myline
        varTTL=$myline
        echo "Voicemail:"$varVM
        echo "Callback:"$varCB
        echo "Has Site:"$varHS
        echo "Other:"$varOT
        echo "No:"$varNO
        echo "Present:"$varPS
        echo "Total:"$varTTL
        echo "End Stats"
        echo ""
        fncMenu
    else
        echo "no session today"
        fncMenu
    fi
    ;;
    2)
    if [ -e ./sessions/$session.dat ]
        then
        exec 3< $session.dat
        read <&3 myline
        varVM=$myline
        read <&3 myline
        varCB=$myline
        read <&3 myline
        varHS=$myline
        read <&3 myline
        varOT=$myline
        read <&3 myline
        varNO=$myline
        read <&3 myline
        varPS=$myline
        read <&3 myline
        varTTL=$myline
        echo "Voicemail:"$varVM
        echo "Callback:"$varCB
        echo "Has Site:"$varHS
        echo "Other:"$varOT
        echo "No:"$varNO
        echo "Present:"$varPS
        echo "Total:"$varTTL
        echo "End Stats"
        echo ""
        fncMenu
    else
        echo "no session for this date"
        fncMenu
    fi
    ;;
    3)
    echo "goodbye"
    break
    ;;
    *)
    echo "unrecognized command"
    fncMenu
    ;;
esac
done

exit
any ideas?
 
Old 08-16-2007, 02:16 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
You need '; then' on line 21

Last edited by slakmagik; 08-16-2007 at 02:19 PM. Reason: misread the second if statement
 
Old 08-16-2007, 02:18 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2401Reputation: 2401Reputation: 2401Reputation: 2401Reputation: 2401Reputation: 2401Reputation: 2401Reputation: 2401Reputation: 2401Reputation: 2401Reputation: 2401
Hi,

It's if ... then .... else.... fi

You are missing the then part after line 21 (if [ -f $date ]).

Hope this helps.
 
Old 08-16-2007, 02:19 PM   #4
projektdotnet
LQ Newbie
 
Registered: Aug 2005
Location: Utah
Distribution: Ubuntu 7.04
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by digiot View Post
You need '; then' on lines 21 and 54
*slaps forehead* I can't believe I missed that part D'OH! Thanks
 
Old 08-16-2007, 02:27 PM   #5
projektdotnet
LQ Newbie
 
Registered: Aug 2005
Location: Utah
Distribution: Ubuntu 7.04
Posts: 7

Original Poster
Rep: Reputation: 0
Here's the fixed version (without the cleaned up version of the output)
Code:
#!/bin/bash

# Date is equal to today's session
date=./sessions/`date +%m%d%y`.dat

# Menu
fncMenu()
{
echo "What date do you want to check?"
echo "1. Today"
echo "2. Other"
echo "3. Exit"
}
fncMenu

while :
do
read selection
case $selection in
    1)
    if [ -f $date ]
        then
        echo "File OK" 
        exec 3< $date
        read <&3 myline
        varVM=$myline
        read <&3 myline
        varCB=$myline
        read <&3 myline
        varHS=$myline
        read <&3 myline
        varOT=$myline
        read <&3 myline
        varNO=$myline
        read <&3 myline
        varPS=$myline
        read <&3 myline
        varTTL=$myline
        echo "Voicemail:"$varVM
        echo "Callback:"$varCB
        echo "Has Site:"$varHS
        echo "Other:"$varOT
        echo "No:"$varNO
        echo "Present:"$varPS
        echo "Total:"$varTTL
        echo "End Stats"
        echo ""
        fncMenu
    else
        echo "no session today"
        fncMenu
    fi
    ;;
    2)
    echo 'What Date? (mmddyy)'
    read session
    file=./sessions/
    file=$file$session
    file=$file'.dat'
    if [ -f ./sessions/$session.dat ]
        then
        exec 4< $file
        read <&4 myline
        varVM=$myline
        read <&4 myline
        varCB=$myline
        read <&4 myline
        varHS=$myline
        read <&4 myline
        varOT=$myline
        read <&4 myline
        varNO=$myline
        read <&4 myline
        varPS=$myline
        read <&4 myline
        varTTL=$myline
        echo "Voicemail:"$varVM
        echo "Callback:"$varCB
        echo "Has Site:"$varHS
        echo "Other:"$varOT
        echo "No:"$varNO
        echo "Present:"$varPS
        echo "Total:"$varTTL
        echo "End Stats"
        echo ""
        fncMenu
    else
        echo "no session for this date"
        fncMenu
    fi
    ;;
    3)
    echo "goodbye"
    break
    ;;
    *)
    echo "unrecognized command"
    fncMenu
    ;;
esac
done

exit
 
Old 08-16-2007, 03:22 PM   #6
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by projektdotnet View Post
Here's the fixed version (without the cleaned up version of the output)
Code:
#!/bin/bash

# Date is equal to today's session
date=./sessions/`date +%m%d%y`.dat

# Menu
fncMenu()
{
echo "What date do you want to check?"
echo "1. Today"
echo "2. Other"
echo "3. Exit"
}
fncMenu

while :
do
read selection
case $selection in
    1)
    if [ -f $date ]
        then
        echo "File OK" 
        exec 3< $date
        read <&3 myline
        varVM=$myline
        read <&3 myline
        varCB=$myline
        read <&3 myline
        varHS=$myline
        read <&3 myline
        varOT=$myline
        read <&3 myline
        varNO=$myline
        read <&3 myline
        varPS=$myline
        read <&3 myline
        varTTL=$myline

Why not:

Code:
    {
        read varVM
        read varCB
        read varHS
        read varOT
        read varNO
        read varPS
        read varTTL
    } < "$date"
(Ditto below.)
Quote:
echo "Voicemail:"$varVM
echo "Callback:"$varCB
echo "Has Site:"$varHS
echo "Other:"$varOT
echo "No:"$varNO
echo "Present:"$varPS
echo "Total:"$varTTL
echo "End Stats"
echo ""
fncMenu
else
echo "no session today"
fncMenu
fi
;;
2)
echo 'What Date? (mmddyy)'
read session
file=./sessions/
file=$file$session
file=$file'.dat'
if [ -f ./sessions/$session.dat ]
then
exec 4< $file
read <&4 myline
varVM=$myline
read <&4 myline
varCB=$myline
read <&4 myline
varHS=$myline
read <&4 myline
varOT=$myline
read <&4 myline
varNO=$myline
read <&4 myline
varPS=$myline
read <&4 myline
varTTL=$myline
echo "Voicemail:"$varVM
echo "Callback:"$varCB
echo "Has Site:"$varHS
echo "Other:"$varOT
echo "No:"$varNO
echo "Present:"$varPS
echo "Total:"$varTTL
echo "End Stats"
echo ""
fncMenu
else
echo "no session for this date"
fncMenu
fi
;;
3)
echo "goodbye"
break
;;
*)
echo "unrecognized command"
fncMenu
;;
esac
done

exit
[/code]
 
Old 08-17-2007, 03:00 AM   #7
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,911

Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
Hello Chris! I didn't know you were a member here. I've recently been using a bit of your code to create some shell-only utilities. You can see the list of what I've got done in this thread:
http://www.linuxquestions.org/questi...d.php?t=577308

Perhaps you have others which could be added to the collection.
 
Old 09-01-2007, 04:32 PM   #8
projektdotnet
LQ Newbie
 
Registered: Aug 2005
Location: Utah
Distribution: Ubuntu 7.04
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by cfaj View Post

Why not:

Code:
    {
        read varVM
        read varCB
        read varHS
        read varOT
        read varNO
        read varPS
        read varTTL
    } < "$date"
(Ditto below.)
touche'. Thanks for the cleaner code although I no longer use the script as I found a basic type language and wrote a gui (gambas) and then decided to stop being so stats oriented.

-Shawn
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
error: unexpected token `newline' CarlosV Programming 4 05-17-2011 04:47 AM
syntax error near unexpected token deskjockey39 Linux - General 2 01-16-2007 09:47 AM
syntax error for unexpected token `(' Steve Spurr Linux - Newbie 6 09-22-2006 09:19 AM
syntax error near unexpected token `else' josedias Programming 3 09-11-2006 08:09 PM
syntax error near unexpected token ` mattyspatty Programming 8 05-07-2006 06:19 PM

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

All times are GMT -5. The time now is 04:36 PM.

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