LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-27-2008, 10:59 PM   #1
nawuza
Member
 
Registered: Jan 2007
Location: High Castle
Distribution: FC8
Posts: 66

Rep: Reputation: 15
Error in script


hello..i am doing a script for checking a file/folder if it exist tin a directory.

the script is in root directory and it looks like this
Code:
#!/bin/bash
if [ -f /root/abc.sh ]; then 
    echo "file found"
else
    echo "file not found"
fi
i got two error:
unexpexted EOF while looking matching
syntax error: unexpected end of file

please help.
 
Old 07-28-2008, 12:02 AM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Script looks fine, what else is in that file?
 
Old 07-28-2008, 12:50 AM   #3
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
You are probably editing the file with an editor that doesn't set the correct line endings. Which editor?

Save your files using Unix style line endings.

You can convert the file with dos2unix, or in vim:

vim file
:set ff=unix
:wq
 
Old 07-28-2008, 04:30 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Even quicker version of

:wq

is

:x
 
Old 07-28-2008, 04:35 AM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
I'm a Shift ZZ guy, but wanted to reinforce the : command twice in a row, so it wouldn't be missed.
 
Old 07-28-2008, 08:16 AM   #6
sir_com
Member
 
Registered: Feb 2008
Posts: 31

Rep: Reputation: 15
Hi nawuza,

The script is absolutely correct and even I have tested in my machine...it works. I suggest that ... if you have copied this from some pdf or document then please copy it again using vi/vim/emacs editor.

As suggested you can also run the dos2unix utility/command like "dos2unix <script-name>" and run the script again. This may solve your problem.


In addition to this you may also try quoting the expression like

-f "/root/abc.sh"

Cheers,
sir_com
 
Old 07-28-2008, 12:49 PM   #7
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Quote:
Originally Posted by sir_com View Post
In addition to this you may also try quoting the expression like

-f "/root/abc.sh"
This makes no difference. There is nothing in the string "/root/abc.sh" that needs protecting from the shell.
 
Old 07-28-2008, 09:32 PM   #8
nawuza
Member
 
Registered: Jan 2007
Location: High Castle
Distribution: FC8
Posts: 66

Original Poster
Rep: Reputation: 15
i edit the script using vi.i will try.
 
  


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
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 10:28 AM
bash script read error and awk ouptut error whited Programming 4 10-16-2007 08:05 PM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 10:10 PM
error when tying to run python script(bash error?) shanenin Programming 5 01-10-2006 11:01 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 05:21 PM


All times are GMT -5. The time now is 06:31 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration