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

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

Post by J Krugma » Sun, 06 Jun 2004 01:01:13



Why is it that, at least under bash, the following snippet

  % perl -e 'print "ok\n"'
  ok

works fine, but this one

  % perl -e <<'EOF'
  > print "ok\n"
  > EOF

fails with the error message

  No code specified for -e.

?

TIA,

jill
--
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.

 
 
 

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

Post by Michael Tos » Sun, 06 Jun 2004 01:15:23



> Why is it that, at least under bash, the following snippet

>   % perl -e 'print "ok\n"'
>   ok

> works fine, but this one

>   % perl -e <<'EOF'
>   > print "ok\n"
>   > EOF

> fails with the error message

>   No code specified for -e.

> ?

> TIA,

> jill
> --
> To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.

-e is an inline script.
Leave it out, and perl reads the commands from stdin
(just as the << delivers):

perl <<'EOF'
print "ok\n"
EOF

--
Michael Tosch
IT Specialist
HP Managed Services Germany
Phone +49 2407 575 313
Mail: michael.tosch:hp.com

 
 
 

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

Post by Barry Margoli » Sun, 06 Jun 2004 01:30:24




Quote:> Why is it that, at least under bash, the following snippet

>   % perl -e 'print "ok\n"'
>   ok

> works fine, but this one

>   % perl -e <<'EOF'
>   > print "ok\n"
>   > EOF

> fails with the error message

>   No code specified for -e.

> ?

The here-document created by <<'EOF' becomes perl's standard input, not
a command-line argument.  You want:

% perl -e "`cat <<'EOF'

Quote:> print "ok\n"
> EOF
> `"

or:

% perl -- <<'EOF'

Quote:> print "ok\n"
> EOF

--

Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
 
 
 

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

Post by J Krugma » Sun, 06 Jun 2004 02:26:48





>> Why is it that, at least under bash, the following snippet

>>   % perl -e 'print "ok\n"'
>>   ok

>> works fine, but this one

>>   % perl -e <<'EOF'
>>   > print "ok\n"
>>   > EOF

>> fails with the error message

>>   No code specified for -e.

>> ?
>The here-document created by <<'EOF' becomes perl's standard input, not
>a command-line argument.  You want:
>% perl -e "`cat <<'EOF'
>> print "ok\n"
>> EOF
>> `"
>or:
>% perl -- <<'EOF'
>> print "ok\n"
>> EOF

Ah!

Many thanks!  (And to Michael too.)

jill
--
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.

 
 
 

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

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

2. Follies from DamnIt.Org

3. <<<<<soundconfig problem <<<<<<<

4. Interactive Postscript interpreter

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

6. How to view a .avi file?

7. Mitsumi <<<--- Linux doesn't see it.

8. IDT77252 SAR device driver for linux

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

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

11. Issuing 'echo <ESC>[r' from .cshrc doesn't work, HELP