Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: perl script inside a shell script

by eg (Friar)
on Dec 12, 2000 at 03:05 UTC ( [id://46173]=note: print w/replies, xml ) Need Help??


in reply to perl script inside a shell script

It's strange and terrible and I'm not sure how to get something out of the perl part, but this sort of works (with bash, at least):

#!/bin/sh echo This is bash i=12 echo $i perl <<__HERE__ print "This is perl\n"; my \$i = $i; print ++\$i . "\n"; __HERE__ echo This is bash again echo $i

Good luck with it (although I'm not quite sure what you hope to gain.)

Replies are listed 'Best First'.
Re: Re: perl script inside a shell script
by chipmunk (Parson) on Dec 12, 2000 at 03:17 UTC
    Very nice! As another way of doing it, using quotes around the here-doc terminator saves you from having to backslash all those special characters.
    #!/bin/sh echo This is bash i=12 echo $i perl - $i <<'__HERE__' my $i = shift; print "This is perl\n"; print ++$i . "\n"; __HERE__ echo This is bash again echo $i
    Because << is a redirection to STDIN, in order to add $i to the command line I also had to add - so that perl would know to read the script from STDIN.
Re: Re: perl script inside a shell script
by Blue (Hermit) on Dec 12, 2000 at 03:14 UTC
    Ewwww.

    I was thinking that it would be pretty trivial to embed Perl one liners in the shell script. This, on the other hand is just ... just .. well, I don't know. Not right. Not even wrong. It just is.

    Hmmm. Barring something like this, or a perl one-liner, I can't think of any easy way to do it in one script that starts as a shell. The shebang (#!) is a one-time-deal, no changing type mid way though.

    BTW, just for curiosity, could you have the base be a Perl program that called shell script stuff? The requirement to have shell and Perl in the same file is somewhat unusual.

    =Blue
    ...you might be eaten by a grue...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://46173]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-09-08 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.