Click to See Complete Forum and Search --> : Syntax errors when running scripts


Mulix
12-04-2001, 02:44 AM
I need to find out what is messing me up at my Linux box at home. I'm taking a Linux class at the community college and at the Lab they have RH 6.2. My scripts run OK at the the Lab. When I take the scripts I wrote in 6.2 to my machine at home with RH 7.2, the scripts stop running and give me error messages. The message happens at the first if - fi block and says "syntax error near unexpected token 'fi'" I'm using vi to edit and copying the files to a floppy.

Does anyone know what should I do to stop these errors?
:confused:

z0mbix
12-04-2001, 06:33 AM
Post the script here, then we have a better idea of what's going on. :)

bigrigdriver
12-04-2001, 03:48 PM
Just off the top of my head, it sounds like you have one too many fi's, or one too few if's.

camelrider
12-04-2001, 04:29 PM
Are you using the same shell on both machines? (bash, csh, et.al.)
;)

Mulix
12-04-2001, 08:57 PM
Here is the code:

#================================================= ==================
# Script Name: CDadd CBIS 223 Lab 06 C N0. 6
# By: Manuel Alonzo
# Date: November 2001
# Purpose: A shell script that sets up a loop to add
# new CDs the the music file.
# The code also prevents duplicate phone
# numbers from being assigned.
#================================================= ==================
trap "rm ~/tmp/* 2> /dev/null; exit" 0 1 2 3
cdfile=~/music
looptest=y
while [ $looptest = y ]
do
clear
cursor 1 4; echo "CD List Additions"
cursor 2 4; echo "=============================="
cursor 3 4; echo "Artist Name "
cursor 4 4; echo "CD name "
cursor 5 4; echo "Date of Purchase "
cursor 6 4; echo "Price "
cursor 8 4; echo "Add Another? (Y)es or (Q)uit "
cursor 3 22; read aname
if [ "$aname" = 'q' ]
then { clear; exit }
fi
cursor 4 22; read cname
cursor 5 22; read date
cursor 6 22; read price
# Check to see if last name is not a blank before you write to disk
if [ "$aname" > " " ]
then
echo "$aname:$cname:$date:$price" >> $cdfile
fi
cursor 8 33; read looptest
if [ "$looptest" = 'q' ]
then { clear; exit }
fi
done

camelrider
12-05-2001, 05:01 AM
Shouldn't the first line of the script call the shell which is to interpret it?

such as : #! /bin/bash, or #! bin/tcsh

There are some syntax differences between shells.

:)

Mulix
12-05-2001, 05:48 PM
I have tried everything: #! /bin/bash, #! /bin/sh, or #! bin/tcsh without success.

Mulix
12-06-2001, 12:58 PM
I tried running "sh script" and still didn't work. I tried rewriting the script and commenting some lines ans it seems that the combination "} fi" is the cause of the syntax errors. I took them out and I don't get errors. However, the script doesn't run as intended. :(