LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   -bash: *.sh: line 25: syntax error: unexpected end of file (http://www.linuxquestions.org/questions/linux-general-1/bash-%2A-sh-line-25-syntax-error-unexpected-end-of-file-800061/)

prashanth212 04-05-2010 03:02 AM

-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

blacky_5251 04-05-2010 03:16 AM

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


prashanth212 04-05-2010 05:20 AM

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

blacky_5251 04-05-2010 05:29 AM

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.

catkin 04-05-2010 06:21 AM

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'


catkin 04-05-2010 06:23 AM

Quote:

Originally Posted by prashanth212 (Post 3924487)
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.

catkin 04-05-2010 06:26 AM

Quote:

Originally Posted by blacky_5251 (Post 3924493)
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.

blacky_5251 04-05-2010 06:55 AM

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.

prashanth212 04-06-2010 12:52 AM

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 :)


All times are GMT -5. The time now is 08:57 PM.