LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Error in script (https://www.linuxquestions.org/questions/linux-newbie-8/error-in-script-658659/)

nawuza 07-27-2008 10:59 PM

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.

crabboy 07-28-2008 12:02 AM

Script looks fine, what else is in that file?

Mr. C. 07-28-2008 12:50 AM

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

chrism01 07-28-2008 04:30 AM

Even quicker version of

:wq

is

:x

Mr. C. 07-28-2008 04:35 AM

I'm a Shift ZZ guy, but wanted to reinforce the : command twice in a row, so it wouldn't be missed.

sir_com 07-28-2008 08:16 AM

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

Mr. C. 07-28-2008 12:49 PM

Quote:

Originally Posted by sir_com (Post 3228599)
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.

nawuza 07-28-2008 09:32 PM

i edit the script using vi.i will try.


All times are GMT -5. The time now is 09:50 PM.