Need help line 35: syntax error: unexpected end of file only 34 lines of code

I am not sure what I am doing wrong here, I did some research and only confused myself further. Any help would be greatly appreciated. I need to make this work for work tomorrow.

There are only 34 lines of code in this script, yet its complaining about line 35

Here is the code:

#!/bin/bash
VUE_SEND_DIR=/blah/send
VUE_GET_DIR=/blah/receive
LC_GET_DIR=/usr/public/blah/blah/CDK/get
LC_SEND_DIR=/usr/public/blah/blah/CDK/send


PS3='Let me know what you would like to do'
LIST="Pull Send EXIT"
select OPT in $LIST
do
if [ $OPT = "Pull" ] &> /dev/null
then
sftp blah@sftp.blah.com <<EOF

        cd $VUE_SEND_DIR
        lcd $LC_GET_DIR
        mget *
        exit
    EOF
elif [ $OPT = "Send" ] &> /dev/null
then
sftp blah@sftp.blah.com <<EOF

        cd $VUE_GET_DIR
        lcd $LC_SEND_DIR
        mget *
        exit
    EOF
elif [ $OPT = "END" ] &> /dev/null
then
exit 0
fi
done

You're missing the final 'else' in your if statement.

Format is:

if
elif
else
fi

Hope this helps.

It works for me:

# ./mySCPScript.sh
1) Pull
2) Send
3) EXIT
Let me know what you would like to do

Try to "vi <script>" and see if there are "^M" in the end of the lines!

If they are there, try: "dos2unix <script>"

Regards.

I am going crazy right now.... did dos2unix about 10 times and still

line 35: syntax error: unexpected end of file

The "EOF" at both the places should begin at column number 1.

The script works in Cygwin Bash if that is fixed.

$
$
$ cat -n f34
     1  #!/bin/bash
     2  VUE_SEND_DIR=/blah/send
     3  VUE_GET_DIR=/blah/receive
     4  LC_GET_DIR=/usr/public/blah/blah/CDK/get
     5  LC_SEND_DIR=/usr/public/blah/blah/CDK/send
     6
     7
     8  PS3='Let me know what you would like to do'
     9  LIST="Pull Send EXIT"
    10  select OPT in $LIST
    11  do
    12  if [ $OPT = "Pull" ] &> /dev/null
    13  then
    14  sftp blah@sftp.blah.com <<EOF
    15
    16          cd $VUE_SEND_DIR
    17          lcd $LC_GET_DIR
    18          mget *
    19          exit
    20      EOF
    21  elif [ $OPT = "Send" ] &> /dev/null
    22  then
    23  sftp blah@sftp.blah.com <<EOF
    24
    25          cd $VUE_GET_DIR
    26          lcd $LC_SEND_DIR
    27          mget *
    28          exit
    29      EOF
    30  elif [ $OPT = "END" ] &> /dev/null
    31  then
    32  exit 0
    33  fi
    34  done
$
$ ./f34
./f34: line 35: syntax error: unexpected end of file
$
$
$ # after editing lines 20 and 29 of the script
$
$ cat -n f34
     1  #!/bin/bash
     2  VUE_SEND_DIR=/blah/send
     3  VUE_GET_DIR=/blah/receive
     4  LC_GET_DIR=/usr/public/blah/blah/CDK/get
     5  LC_SEND_DIR=/usr/public/blah/blah/CDK/send
     6
     7
     8  PS3='Let me know what you would like to do'
     9  LIST="Pull Send EXIT"
    10  select OPT in $LIST
    11  do
    12  if [ $OPT = "Pull" ] &> /dev/null
    13  then
    14  sftp blah@sftp.blah.com <<EOF
    15
    16          cd $VUE_SEND_DIR
    17          lcd $LC_GET_DIR
    18          mget *
    19          exit
    20  EOF
    21  elif [ $OPT = "Send" ] &> /dev/null
    22  then
    23  sftp blah@sftp.blah.com <<EOF
    24
    25          cd $VUE_GET_DIR
    26          lcd $LC_SEND_DIR
    27          mget *
    28          exit
    29  EOF
    30  elif [ $OPT = "END" ] &> /dev/null
    31  then
    32  exit 0
    33  fi
    34  done
$
$ ./f34
1) Pull
2) Send
3) EXIT
Let me know what you would like to do<CTRL+C>
$
$

tyler_durden

Probably this is not the problem!

When you "vi <script>", can you see "^M"?

Also, add this line write after the interpreter:

set -xv

Run the script and check the output to see if it helps you.

---------- Post updated at 15:40 ---------- Previous update was at 15:33 ----------

This will solve your problem, that's why it worked for me! When I copied/pasted, the "EOF" went back to the first column. =o)

Thanks Guys!

Column number 1..... a couple of spaces caused me so much headache. You guys are awesome on this board!

Before you forget, you should put that into your ~/.exrc so vi always has it on your login!

One of my vi interview question answers was, to see hidden characters on a one time basis, ":.l". I missed that one, but they hired me.

I use "cat -vte" on problem files, too, to see control characters and spaces/tabs at end of line. It even works to look around in binary file streams without linefeeds.

It feels easier to see problems with "cat -vte" than with the more aggressive "od -bc", where lines are merged into a rectangle of dump.

I use << rarely, not because Imight forget that the control string must be on a line absolutely by itself, but because I like the finer control and the pipe-friendly data-up-front flavor of echo pipe to achieve the same end:

echo 'No $meta char in here
but \\.
'"You get expansion in here for $sure
"' but not $(here)!
' | whatever | more_stuff | more_yet | ssh2 some_host ksh

I usually start out my echo with the single quote and for stuff that needs expansion use the double quotes, like "$variable_name" or nothing, like $( command inline data generator ), which is somewhat implicitly protected.

This works especially well if you want the commands to run on a remote host, since the single quote keeps all the remote metadata unexpanded without individual escapes. Why write two scripts, when you can keep all the process in one, in sync.?