LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-05-2010, 02:02 AM   #1
prashanth212
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Rep: Reputation: 0
Smile -bash: *.sh: line 25: syntax error: unexpected end of file


Hi, I am new linux platform.
I am just executing some shell script which is given below
Quote:
#!/bin/bash

echo

# Change JAVA to point to the real java
JAVA=/usr/bin/java

if ! $JAVA -version 2>&1|grep -q 1.6
then
echo "JAVA version is not correct. The supported version must be at least 1.6."
exit 1
fi

if ! $JAVA -server 2>&1| grep -q -i Error:
then
JAVA_OPTS='-server'
fi

if $JAVA -version 2>&1| grep -q -i SAP
then
JAVA_OPTS=$JAVA_OPTS' -XtraceFile=log/vm_@PID_trace.log'
fi

$JAVA $JAVA_OPTS -Dljs.command.port=2222 -Dcom.sun.management.jmxremote.port=1717 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dosgi.requiredJavaVersion=1.6 -Dosgi.install.area=. -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Dorg.eclipse.equinox.simpleconfigurator.exclusiveInstallation=false -jar plugins/com.sap.js.startup.jar -console

exit 0
when i tried to run this script i got the error saying ..
"-bash: go.sh: line 26: syntax error: unexpected end of file"

when i debugged through "bash -x -v go.sh" command.. i got the following output

Quote:
#!bin/bash

+ $'\r'
: command not found
echo
+ $'echo\r'
: command not found

+ $'\r'
: command not found
# Change JAVA to point to the real java
JAVA=/usr/bin/java
+ JAVA=$'/usr/bin/java\r'

+ $'\r'
: command not found
if ! $JAVA -version 2>&1|grep -q 1.6
then
echo "JAVA version is not correct. The supported version must be at least 1.6."
exit 1
fi

if ! $JAVA -server 2>&1| grep -q -i Error:
then
JAVA_OPTS='-server'
fi

if $JAVA -version 2>&1| grep -q -i SAP
then
JAVA_OPTS=$JAVA_OPTS' -XtraceFile=log/vm_@PID_trace.log'
fi
$JAVA $JAVA_OPTS -Dljs.command.port=2222 -Dcom.sun.management.jmxremote.port=1717 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dosgi.requiredJavaVersion=1.6 -Dosgi.install.area=. -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Dorg.eclipse.equinox.simpleconfigurator.exclusiveInstallation=false -jar plugins/com.sap.js.startup.jar -console

exit 0
go.sh: line 26: syntax error: unexpected end of file
when i run the command "od -c go.sh", I got the following error

Quote:
0000000 # ! b i n / b a s h \r \n \r \n e c
0000020 h o \r \n \r \n # C h a n g e J
0000040 A V A t o p o i n t t o
0000060 t h e r e a l j a v a \r \n J
0000100 A V A = / u s r / b i n / j a v
0000120 a \r \n \r \n i f ! $ J A V A
0000140 - v e r s i o n 2 > & 1 | g r
0000160 e p - q 1 . 6 \r \n t h e n \r
0000200 \n e c h o " J A V A v e r
0000220 s i o n i s n o t c o r r
0000240 e c t . T h e s u p p o r t
0000260 e d v e r s i o n m u s t
0000300 b e a t l e a s t 1 . 6 .
0000320 " \r \n e x i t 1 \r \n f i \r \n
0000340 \r \n i f ! $ J A V A - s e
0000360 r v e r 2 > & 1 | g r e p
0000400 - q - i E r r o r : \r \n t h
0000420 e n \r \n J A V A _ O P T S = '
0000440 - s e r v e r ' \r \n f i \r \n \r \n
0000460 i f $ J A V A - v e r s i o
0000500 n 2 > & 1 | g r e p - q
0000520 - i S A P \r \n t h e n \r \n J
0000540 A V A _ O P T S = $ J A V A _ O
0000560 P T S ' - X t r a c e F i l e
0000600 = l o g / v m _ @ P I D _ t r a
0000620 c e . l o g ' \r \n f i \r \n $ J A
0000640 V A $ J A V A _ O P T S - D
0000660 l j s . c o m m a n d . p o r t
0000700 = 2 2 2 2 - D c o m . s u n .
0000720 m a n a g e m e n t . j m x r e
0000740 m o t e . p o r t = 1 7 1 7 -
0000760 D c o m . s u n . m a n a g e m
0001000 e n t . j m x r e m o t e . a u
0001020 t h e n t i c a t e = f a l s e
0001040 - D c o m . s u n . m a n a g
0001060 e m e n t . j m x r e m o t e .
0001100 s s l = f a l s e - D o s g i
0001120 . r e q u i r e d J a v a V e r
0001140 s i o n = 1 . 6 - D o s g i .
0001160 i n s t a l l . a r e a = . -
0001200 D e c l i p s e . i g n o r e A
0001220 p p = t r u e - D o s g i . n
0001240 o S h u t d o w n = t r u e -
0001260 D o r g . e c l i p s e . e q u
0001300 i n o x . s i m p l e c o n f i
0001320 g u r a t o r . e x c l u s i v
0001340 e I n s t a l l a t i o n = f a
0001360 l s e - j a r p l u g i n s
0001400 / c o m . s a p . j s . s t a r
0001420 t u p . j a r - c o n s o l e
0001440 \r \n \r \n e x i t 0 \r \n
Could you please help me in resolving this problem ASAP.

Thanks in advance,
Prashanth
 
Old 04-05-2010, 02:16 AM   #2
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569

Rep: Reputation: 54
Put your tests inside square brackets [ ], and you need to force the execution of your commands with $(command) syntax. E.g.:-
Code:
if [ ! "$($JAVA -version 2>&1|grep -q 1.6)" ]
then
....
fi

Last edited by blacky_5251; 04-05-2010 at 02:19 AM. Reason: Added the all important quote marks
 
Old 04-05-2010, 04:20 AM   #3
prashanth212
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for the quick reply.

I made the suggested changes. But still the problem persists.
But as a workaround, I created a new file and copied each statement from the original file and pasted into new file. Now the script working fine.

Anyway, i want the solution for my actual problem.

Thanks,
Prashanth
 
Old 04-05-2010, 04:29 AM   #4
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569

Rep: Reputation: 54
It seems your file originated from Windows Land. Each line is terminated with carriage-return and line-feed. A shell-script should only have line-feed record terminators. Perhaps use "dos2unix" to convert the file and try again.
 
1 members found this post helpful.
Old 04-05-2010, 05:21 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,524
Blog Entries: 27

Rep: Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175
The script fails because the if command has to be followed by a test. Possible tests are test, [ ] and [[ ]]. Of these [[ ]] is preferred for reasons given here. These tests enclose Bash Conditional Expressions which allow you to test files, numbers and strings. You may capture the return code from a command and then test it:
Code:
<command>
rc=$?
if [[ $rc -ne 0 ]];then
    <error message about <command> returning $rc>
fi
An alternative bash idiom is <command1> && <command2> || <command3>. This executes command1; if it returns 0 then command2 is run otherwise command3 is run. Each of these commands may actually be several commands if they are a pipleline, a subshell or in a { } group.

Here's an untested rewrite of part of the script using the last technique.
Code:
#!/bin/bash

echo

# Change JAVA to point to the real java
JAVA=/usr/bin/java

$JAVA -version 2>&1 | grep -q 1.6 || {
    echo "JAVA version is not correct. The supported version must be at least 1.6." >&2  # Erro messages are conventionally and usefully written to fd2, stderr
    exit 1;  # The ; is required to end commands in a { }
}

$JAVA -server 2>&1 | grep -q -i 'Error:' || JAVA_OPTS='-server'
 
Old 04-05-2010, 05:23 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,524
Blog Entries: 27

Rep: Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175
Quote:
Originally Posted by prashanth212 View Post
when i tried to run this script i got the error saying ..
"-bash: go.sh: line 26: syntax error: unexpected end of file"
That's because the if-then-fi is not correct.
 
Old 04-05-2010, 05:26 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,524
Blog Entries: 27

Rep: Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175
Quote:
Originally Posted by blacky_5251 View Post
Put your tests inside square brackets [ ], and you need to force the execution of your commands with $(command) syntax. E.g.:-
Code:
if [ ! "$($JAVA -version 2>&1|grep -q 1.6)" ]
then
....
fi
Hello blacky_5251

I don't think that will work because the -q grep option means "$($JAVA -version 2>&1|grep -q 1.6)" will always produce an empty string so the test result will always be the same. OK if the -q option is removed.
 
Old 04-05-2010, 05:55 AM   #8
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569

Rep: Reputation: 54
Quite right Catkin. Ditch the "-q" from the grep statement.

OP: Get your if test working at the command line before you try to put it into your script.
 
Old 04-05-2010, 11:52 PM   #9
prashanth212
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for one and all for your suggestions. The problem is resolved.

The script is written on windows platform. So, I used WinVi editor to write the script again and now everything is fine.

Thanks,
Prashanth
 
  


Reply

Tags
end, file


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash line 74: syntax error: unexpected end of file help? andycol Linux - General 5 09-14-2009 08:12 AM
Bash script -----------syntax error: unexpected end of file ArthurHuang Programming 2 05-01-2009 10:29 AM
Bash script - syntax error: unexpected end of file Mr Pink Programming 7 12-19-2008 06:31 AM
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 09:28 AM
/usr/bin/lesspipe: line 223: syntax error: unexpected end of file fakie_flip Linux - Software 1 09-06-2006 02:22 AM


All times are GMT -5. The time now is 08:21 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration