0
votes

could u help me out? I run this on cygwin as ./test.sh and I get unexpected end of file on line 51. Any thoughts?

Thx in advance

LAST EDIT: final version 'runnin on CygWin, the problem was with the line break, CrLf instead Lf.

#!/bin/sh
##################################################
## USAGE
##################################################
if [ $# -ne 1 ]; then
    echo "1>Use Extractor: $0 <MODO DE OPERACAO>"
    echo "2>Use Extractor: $0 <MODO DE OPERACAO> <DATA INICIAL> <DATA FINAL>"
    exit 127
else
    if [ $1 -lt 0 ]; then
        if [ $1 -gt 1 ]; then
            echo "2>Use Extractor: $0 <MODO DE OPERACAO> <DATA INICIAL> <DATA FINAL>"
            exit 127
        fi
    fi
fi
##################################################
## VARS
##################################################

    ##########################################
    ## AUX
    ##########################################
    set java_cmd=""
    set java_cmd_emergencial=""
    set java_cp=""

    ##########################################
    ## JAR
    ##########################################
    set db_user=""
    set db_pwd=""
    set conn_string=""
    set work_dir=""
    set output_dir=""


##################################################
## PARAMETROS
##################################################
set mode=$1
set data_ini=""
set data_fim=""
if [ $# -eq 3 ]; then
    set data_ini    = $2
    set data_fim    = $3
fi

##################################################
## CHAMADA DO JAR
##################################################
java  "$java_cp" "$java_cmd" "$mode" "$db_user" "$db_pwd" "$conn_string" "$work_dir" "$output_dir"
4
Code is not well indented.. indent it and point line 51 - Emilio
So the question is to find the line number and then find the error? - Learning
Emilio: its quite indented, line 51 is the last line at the file tho :/ Learnin: The question is whether if has an error or not, since i don't have full acess to linux server to test it, i'm testing on cygwin, maybe thats the error after all. - Diego Magalhães
see my posting below, the spacing in the setting of the variables could be causing issues. also fixed the if, which was gt instead of -gt. - sfossen
All solved, thanks all for the tips, the problem was the windows editor saving in windows format (CrLf) instead of Unix (Lf). Thanks all for the tips, masked the answer who made me look for format of the file. - Diego Magalhães

4 Answers

3
votes

"set" isn't bash syntax. Instead of "set foo = bar", you want "foo=bar".

Note: I wrote the corrected form without spaces for a reason. It has to be written that way. Your updated question is still wrong.

2
votes

If nothing else double-check that you have a newline at the end of the last line in the script.

2
votes

Runs for me without errors on MacOS X 10.5.6, except for this line:

if [ $1 -lt 0 -o gt 1 ];

should be

if [ $1 -lt 0 -o $1 -gt 1 ];

I make no comment on whether the rest of the script actually does what it's supposed to...

2
votes

You'll probably want to quote the required fields on the last line. As right now it'll be a blank instead of "".

eg

java  "$java_cp" "$java_cmd" "$mode" "$db_user" "$db_pwd" "$conn_string" "$work_dir" "$output_dir"

edited to atleast run java on mysystem:

#################################################
#!/bin/sh
##################################################
## USAGE
##################################################
if [ $# -ne 1 ]; then
    echo "1>Use Extractor: $0 <MODO DE OPERACAO>;"
    echo "2>Use Extractor: $0 <MODO DE OPERACAO> <DATA INICIAL> <DATA FINAL>"
    exit 127
else
    if [ $1 -lt 0 -o $1 -gt 1 ]; then
        echo "1>O Parametro <MODO DE OPERACAO> deve ser 0 (Cartorios) ou 1 (Transacoes);"
        exit 127
    fi
fi
##################################################
## VARS
##################################################

    ##########################################
    ## AUX
    ##########################################
    java_cmd=""
    java_cmd_emergencial=""
    java_cp=""

    ##########################################
    ## JAR
    ##########################################
    db_user=""
    db_pwd=""
    conn_string=""
    work_dir=""
    output_dir=""


##################################################
## PARAMETROS
##################################################
mode=$1
data_ini=""
data_fim=""
if [ $# -eq 3 ]; then
    data_ini=$2
    data_fim=$3
fi

##################################################
## CHAMADA DO JAR
##################################################
java  $java_cp $java_cmd $mode $db_user $db_pwd $conn_string $work_dir $output_dir