LinuxQuestions.org
Review your favorite Linux distribution.
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 01-25-2006, 11:39 PM   #1
semaja2
LQ Newbie
 
Registered: Jan 2006
Posts: 14

Rep: Reputation: 0
BASH : syntax error


Hey guys i make alot of bash scripts on windows in notepad2 but when i upload them to my suse 10 box they all end up with this error

./newconfig: line 71: syntax error near unexpected token `done'
./newconfig: line 71: `done'

I have checked the scripts with vim and removed extra formatting but the scripts still fail, even if i copy and paste into vim

Code:
#!/bin/bash

function menuinfo {
echo Welcome to the Kings LAN gamer server config edit script
echo
echo "This script was built by Andrew James (semaja2)"
echo
echo This script will allow you to edit the configs for $1
echo with ease.
echo
echo This script is licensed under the GPL, and is only to be used for no profit
echo
echo
echo Select the menu number for the config you want to edit
}



clear
menuinfo

EDIT="plugins.ini server.cfg users.ini"
select edt in $EDIT; do


	if [ "$edt" = "plugins.ini" ]; then
	
	echo Editing plugins.ini for $1
	
	vi /home/gserver/games/$1/addons/amxmodx/configs/plugins.ini
	
	clear
	
	menuinfo
	
	if [ "$edt" = "server.cfg" ]; then
	
	echo Editing plugins.ini for $1
	
	vi /home/gserver/games/$1/server.cfg
	
	clear
	
	menuinfo
	
	if [ "$edt" = "users.ini" ]; then
	
	echo Editing plugins.ini for $1
	
	vi /home/gserver/games/$1/addons/amxmodx/configs/users.ini
	
	clear
	
	menuinfo
	
	else
	
	clear
	menuinfo
	echo
	echo
	echo ERROR : BAD SELECTION, TRY AGAIN
	fi
done
 
Old 01-25-2006, 11:52 PM   #2
bobbelfield
Member
 
Registered: Jan 2006
Location: Australia
Distribution: Mandriva 2006
Posts: 154

Rep: Reputation: 30
Put a new line under done and try it again
Keep a new line under all scripts
 
Old 01-25-2006, 11:57 PM   #3
semaja2
LQ Newbie
 
Registered: Jan 2006
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bobbelfield
Put a new line under done and try it again
Keep a new line under all scripts
nope that didnt fix it
 
Old 01-26-2006, 12:22 AM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
replace the middle two ifs with elif..
Code:
if [ "$edt" = "plugins.ini" ]; then
    echo Editing plugins.ini for $1
    vi /home/gserver/games/$1/addons/amxmodx/configs/plugins.ini
    clear
    menuinfo


    elif [ "$edt" = "server.cfg" ]; then
    echo "Editing plugins.ini for $1"
    vi /home/gserver/games/$1/server.cfg
    clear
    menuinfo


    elif [ "$edt" = "users.ini" ]; then
    echo Editing plugins.ini for $1
    vi /home/gserver/games/$1/addons/amxmodx/configs/users.ini
    clear
    menuinfo

    else
    clear
    menuinfo
    echo
    echo
    echo ERROR : BAD SELECTION, TRY AGAIN
    fi
 
Old 01-26-2006, 12:28 AM   #5
rylan76
Senior Member
 
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,552

Rep: Reputation: 103Reputation: 103
I experienced something similar once with bash scripts originating in Windows for MingW. I think I did

dos2unix

on the .sh files before executing them in Linux. Have you tried this?

I think it is the DOS / Windows format of line end indications that are giving you the problem (CR/LF's instead of just CR's? Or is it LF's? Unsure).

Anyway, dos2unix converts textfiles, maybe it will help.
 
Old 01-26-2006, 12:30 AM   #6
bobbelfield
Member
 
Registered: Jan 2006
Location: Australia
Distribution: Mandriva 2006
Posts: 154

Rep: Reputation: 30
Sorry im not too good on scripts yet but I notice there are 3 if statements and only one fi . Would that work? Have to leave it to someone else .

Edit Piped at the post ..good stuff

Last edited by bobbelfield; 01-26-2006 at 12:33 AM.
 
Old 01-26-2006, 12:33 AM   #7
semaja2
LQ Newbie
 
Registered: Jan 2006
Posts: 14

Original Poster
Rep: Reputation: 0
ahh your right thanks so much, i clearly over looked the if statments which were ment to be elif, thanks again


ill also look at that dos2unix converter becuase i really like notepad2 since it colours parts of code to make it easier to edit
 
  


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
explanation on some bash syntax slzckboy Programming 2 10-02-2005 06:06 AM
Bash For Loops gives syntax error meadensi Linux - Newbie 2 02-23-2005 10:30 AM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
BASH - simple script issue - syntax? tw1ggy5 Programming 11 05-21-2004 09:09 AM
help with basic syntax in bash script Supp0rtLinux Linux - Software 4 03-27-2003 06:57 PM

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

All times are GMT -5. The time now is 10:33 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