![]() |
-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:
"-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:
Quote:
Thanks in advance, Prashanth |
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)" ] |
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 |
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.
|
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>Here's an untested rewrite of part of the script using the last technique. Code:
#!/bin/bash |
Quote:
|
Quote:
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. |
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. |
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 11:53 AM. |