what does << do and why doesn't it work inside of an if

what does << do and why doesn't it work inside of an if

Post by Mike » Sun, 30 Mar 2003 07:26:46



I'm trying to write a bash script.
I'm using:
        ftp -n -i << END_FTP
        open $mydomain
        user $myusername $mypassword
        cd $subdirremote
        ls
        mput *
        bye
        END_FTP

which works fine .. UNTIL I put it inside an if statement.. then I get an
error: line .. unexpected end of file. What would cause this?
Maybe it would help if I understood what the << is really doing for me.
I thought it just told the script to use the following series of commands
until it ran across the specified string (END_FTP in this case) but perhaps
I misunderstood. I tried removing the variablels and replacing wtih real
information but it still did the same thing..
Thanks.
~Mike

 
 
 

what does << do and why doesn't it work inside of an if

Post by Aaron Baughe » Sun, 30 Mar 2003 08:17:09



> I'm trying to write a bash script.
> I'm using:
>         ftp -n -i << END_FTP
>         open $mydomain
>         user $myusername $mypassword
>         cd $subdirremote
>         ls
>         mput *
>         bye
>         END_FTP
> which works fine .. UNTIL I put it inside an if statement.. then I
> get an error: line .. unexpected end of file. What would cause this?

My guess is that you're indenting the END_FTP marker.  That won't
work; the shell expects to find it at the beginning of a line.  So it
looks all the way to the end of the file for it, gives up, and then
can't find your closing 'fi' because it's past it already.

If you really want to indent your ending marker, you can add the same
spacing to the opening marker:

if true; then
  cat << "  END_FTP"
Howdy....
  END_FTP
fi

By using quotes, I added two spaces to the << marker, to match my
closing marker later.

Quote:> Maybe it would help if I understood what the << is really doing for
> me.  I thought it just told the script to use the following series
> of commands until it ran across the specified string (END_FTP in
> this case) but perhaps I misunderstood.

Maybe a little.  The << notation says to take the text between here
(that's why it's called a 'here' document) and the matching closing
text, and feed it to the standard input of the command.  So your
example feeds those lines to the ftp process that's started.  It
should work, once you fix the indentation.

--
Aaron


 
 
 

what does << do and why doesn't it work inside of an if

Post by Stephen Paskalu » Sun, 30 Mar 2003 08:43:13




>> which works fine .. UNTIL I put it inside an if statement.. then I
>> get an error: line .. unexpected end of file. What would cause this?

> My guess is that you're indenting the END_FTP marker.  That won't
> work; the shell expects to find it at the beginning of a line.  So it
> looks all the way to the end of the file for it, gives up, and then
> can't find your closing 'fi' because it's past it already.

You could also use <<- instead of << to strip all leading tabs
from the each line in the script, allowing you to keep sensible
indenting.  I'm assuming that the indenting is the problem here.

This indenting issue is described quite directly in the bash
man page.

--
Stephen Paskaluk
4th Year Computer Engineering
University of Alberta

 
 
 

what does << do and why doesn't it work inside of an if

Post by Mike » Tue, 01 Apr 2003 01:20:20


Excellent! Thanks Aaron and Stephen. You hit it exactly and with that
overlooked bit of information and a few more references to the manuals and
a couple online tutorials my script is working, at least to some extent,
now.

I have to wonder though if I'm re-inventing the wheel. In Windows I have
text editor I'm fond of. EditPlus2 ( www.editplus.com ) allows me to set up
ftp configurations so that I can choose to open remote file, select a file
listed and retrieved via ftp and when I choose Save it uploads the changed
file, also via ftp.

It is really a pretty smooth transaction, "Open Remote - ftp.mydomain1.com -
file I want" and edit then save.

I'd like to do about the same thing with Kate. Currently I'm using a script
that does the uploading and downloading for me and have a Button to launch
it but it would be better if somebody had done something more advanced.

If anybody knows of something this easy I'd be interested in seeing it.

~Mike

 
 
 

what does << do and why doesn't it work inside of an if

Post by Jim Richardso » Thu, 03 Apr 2003 15:53:44


On Sun, 30 Mar 2003 16:20:20 GMT,


> Excellent! Thanks Aaron and Stephen. You hit it exactly and with that
> overlooked bit of information and a few more references to the manuals and
> a couple online tutorials my script is working, at least to some extent,
> now.

> I have to wonder though if I'm re-inventing the wheel. In Windows I have
> text editor I'm fond of. EditPlus2 ( www.editplus.com ) allows me to set up
> ftp configurations so that I can choose to open remote file, select a file
> listed and retrieved via ftp and when I choose Save it uploads the changed
> file, also via ftp.

> It is really a pretty smooth transaction, "Open Remote - ftp.mydomain1.com -
> file I want" and edit then save.

> I'd like to do about the same thing with Kate. Currently I'm using a script
> that does the uploading and downloading for me and have a Button to launch
> it but it would be better if somebody had done something more advanced.

> If anybody knows of something this easy I'd be interested in seeing it.

> ~Mike

just enter the ftp://url in the open file requestor, kate will happily
retrieve it. Permissions permitting, allow you to write it also.

--
Jim Richardson         http://www.eskimo.com/~warlock
A bad day, is when aliens attack, the dog bites you, and your boss tells
 you that the new client wants to make a few changes before delivery.
Linux, super computers, office computers, or home computers, it works.

 
 
 

1. <<<<<soundconfig problem <<<<<<<

hi,
I have a PC100 m747 mainboard
with onboard SIS AGP 6326 8meg videocard
with onboard Sound 3d with sounblaster 16 and WSS support

my SIS videocard works fine
i have problems to configure the soundcard
it claims to be soundblaster compatible , but installing a
'sounblaster 16' , 'soundblaster pro' 'WSS' 'MAD16' has no effect
just "modprobe: devive is busy or not found"

--
Microsoft, just the product of a society
     that's lost it's good manners

--
Microsoft, just the product of a society
     that's lost it's good manners

--
Microsoft, just the product of a society
     that's lost it's good manners

2. Kill Post - inn

3. I need a example of X .twmrc file PLEASE <<<<<<<<<<<<<<<<<<<<<

4. non-EIDE with big disk

5. SOLARIS 2.3 NOT getting the NAMESERVER <<<<<<<<<<<<<<<<<<<<

6. Where can I get SCO UNIX commands overview etc.

7. Script for makeing whole bunch of account of sol. 2.3 <<<<<<<<<<<<<<<<<

8. Cqn I chqnge keyboqrd type ?

9. Why: perl -e <<'EOF' doesn't work (bash)

10. CDE <<<<<<<<<-------------- Need Help !

11. How can grep the 8th of Field <<<<<<<<

12. How can I trap a user in script <-<-<-<-<-<-<-<-

13. I think I've found the rectum of the internet.<<<<<<<<<<<<