1

Source code:

#!/bin/bash
echo "Parametro is $1"
if [ $1 -gt 9 ]
    then
    echo "entre al if";
fi
echo"Fin del script";

My bash file has execute permission:

 -rwxrwxr-x 1 mzadmin mzadmin 108 Feb 15 13:07 test.sh

I run my bash file like:

bash test.sh 9

And the output is:

Parametro is 9
test.sh: line 8: syntax error: unexpected end of file.
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • The posted script doesn't *have* a line 8. – chepner Feb 15 '18 at 20:00
  • @chepner Interestingly, the error does get reported on line 8. This happens both with and without a terminating linefeed on line 7. – that other guy Feb 15 '18 at 20:43
  • 1
    This is probably due to carriage returns. See [Why is a shell script giving syntax errors when the same code works elsewhere?](https://stackoverflow.com/questions/31886144/why-is-a-shell-script-giving-syntax-errors-when-the-same-code-works-elsewhere) – that other guy Feb 15 '18 at 21:00

2 Answers2

2

You need a space after echo command : echo"Fin del script";

So :

echo "Fin del script"

Next time, before asking human help, please pass your script online on http://www.shellcheck.net/ (even if this particular error is not detected, because the shell think echo"Fin del script"; is a unknown command...)

Edit

If you don't have output it's because you use in your test -gt (is greater) but instead you need -ge is greater or equal.

Better use bash arithmetic like this, it's more readable and less error prone :

if ((arg >= 9)); then
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
0

You need to put a newline at the end of your script, because sometimes things don't work properly if they can't find a newline character. See Why should text files end with a newline?

H. Din
  • 41
  • 5
  • thaks, but I solved this mistake and the output is the same ;( ;(. #!/bin/bash echo "Parametro is $1" if [ "$1" -gt 9 ] then echo "entre al if" fi echo "Fin del script" I put two newline at the end. :( – Everardo Flores Quiroz Feb 15 '18 at 21:20
  • thanks guys. I solved my error. the source code is ok, but I am working in windows and after put my file.sh to the Server linux and something is wrong with this case. If I create my file.sh in the server using "vi filename.sh" and I type the same source code, save and after execute "bash filename.sh" everything works fine. – Everardo Flores Quiroz Feb 16 '18 at 15:04