Operating System - Linux
1829737 Members
1872 Online
109992 Solutions
New Discussion

Re: shell function + "<<" got error.

 
Warren_9
Honored Contributor

shell function + "<<" got error.

HI,

my shell script contain a ftp function

ftp ()
{
ftp HOSTNAME << EOF > /dev/null 2>&1
username....
...
..
EOF
}

don't know why it got a syntax error ...

"Syntax error at line 15 : `<<' is not matched."

any idea?

thanks

WAR.


7 REPLIES 7
Peter Godron
Honored Contributor

Re: shell function + "<<" got error.

Hi,
change your function name from ftp (reserved name). Also shouldn't HOSTNAME be $HOSTNAME
For earlier solutions please see:
#! /usr/bin/sh

ip_address=a.b.c.d
user=user
password=password

ftp -n $ip_address << EOF
user $user $password
cd /tmp
lcd /tmp
bin
mput *
bye
EOF

or
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=991609

Ivan Krastev
Honored Contributor

Re: shell function + "<<" got error.

I think the error is in space before EOF.

here is from example :

#!/bin/sh
ftp -n host > ftp.log <<-EOF
user ftp ftp_password
asc
get test123
quit
EOF


regards,
ivan
Warren_9
Honored Contributor

Re: shell function + "<<" got error.

Hi,

the ftp script work if it is not call in the function.

my problem is when the "<<" use in the function , it got an syntax error...

any idea?

Thanks!

WAR.
Peter Godron
Honored Contributor

Re: shell function + "<<" got error.

Warren,
please test:
#!/usr/bin/sh
ftpr ()
{
echo " Starting ftpr"
/usr/bin/ftp -n $1 << EOF > ftpdata.log 2>&1
user ftpuserid ftpuserpwd
ls
quit
EOF
echo "Leaving ftpr"
}
echo "Before the call"
ftpr 10.10.10.10
echo "After the call"
James R. Ferguson
Acclaimed Contributor

Re: shell function + "<<" got error.

Hi Warren:

While somewhat misleading, this error simply indicates that your EOF marker is *not* absolutely flush-left without prepended spaces.

Your 'EOF' must begin in column-1 without any leading spaces or tabs!

If you use the syntax:

... <<- EOF
...
EOF

...where only *tabs* are used to indent, you may beautify your code. Note the "-" appended to the redirection.

Regards!

...JRF...
Peter Nikitka
Honored Contributor

Re: shell function + "<<" got error.

Hi Warren,

I think your contruct results in a recursive call of your function:
The 'ftp' in your 'ftp' function will NOT call /usr/bin/ftp but the funtion itself again.
CHange the name of your function or you /usr/bin/ftp in the function body.

mfG Peter

PS: Nevertheless your 'EOF' marker has to be left adjusted.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Warren_9
Honored Contributor

Re: shell function + "<<" got error.

no solution.... case close!!