make "perl sh_script", "sh sh_script" both work

make "perl sh_script", "sh sh_script" both work

Post by Michael Wa » Tue, 14 Mar 2000 04:00:00



I can execute the following perl scripts under either shell or Perl
====

         if 0;
 [perl scripts ...]
====
 i.e.
 sh script
 perl script

 How do I execute a sh script under either shell or Perl
 simililar to what shown above? i.e.

====
  something understood by both Perl and Shell
 [sh scripts ...]
====

Thanks.
--
Michael Wang

http://www.mindspring.com/~mwang    

 
 
 

make "perl sh_script", "sh sh_script" both work

Post by Decklin Foste » Thu, 16 Mar 2000 04:00:00



> How do I execute a sh script under either shell or Perl
> simililar to what shown above? i.e.

This works for me:


# sh scripts

--
Written with 100% free software. Please support the following websites:
www.debian.org www.noamazon.com www.gnu.org www.opendvd.org lpf.ai.mit.edu

 
 
 

make "perl sh_script", "sh sh_script" both work

Post by Michael Wa » Fri, 17 Mar 2000 04:00:00



>> How do I execute a sh script under either shell or Perl
>> simililar to what shown above? i.e.

>This works for me:


># sh scripts

It does not work for me. See below:

[pizza:/opt/home/mwang/Shell]cat colon.ksh


/bin/ps

[julie:/opt/home/mwang/Shell]perl -w colon.ksh
Bareword found where operator expected at colon.ksh line 3, near "/bin/ps"
        (Missing operator before ps?)
Unquoted string "ps" may clash with future reserved word at colon.ksh line 3.
syntax error at colon.ksh line 3, next token ???
Execution of colon.ksh aborted due to compilation errors.
--
Michael Wang

http://www.mindspring.com/~mwang    

 
 
 

make "perl sh_script", "sh sh_script" both work

Post by Decklin Foste » Mon, 20 Mar 2000 04:00:00



> /bin/ps

Ah-reer-reer-reer. I should have come up with some more complicated
commands to test with[0] before I posted that. Well, at least we all know
my script was just a rather flaky hack.

I'm still interested in solving this, though. The big problem here is
that perl slurps up the whole file and compiles it before running
anything, unlike sh which works line-at-a-time. Going from sh to Perl,
we can have a sh syntax error on the second line, but going the other
way doesn't afford us this luxury.

Hrm. My first though is to quote the whole script in a here document
somehow. I'll think about the ramifications of this and post again if
I come up with another gross kludge.

Anyway, for the Perl gurus... why does that : at the beginning of the
line work? Null line label? I discovered it by accident when I was
mucking around with foo ? bar : baz syntax.

[0] for the record, "echo this is the shell" (newline) "ls". I promise
to go read trip.rc as penance.

--
Written with 100% free software. Please support the following websites:
www.debian.org www.noamazon.com www.gnu.org www.opendvd.org lpf.ai.mit.edu

 
 
 

make "perl sh_script", "sh sh_script" both work

Post by Ken Pizzi » Wed, 22 Mar 2000 04:00:00



>I'm still interested in solving this, though. The big problem here is
>that perl slurps up the whole file and compiles it before running
>anything, unlike sh which works line-at-a-time. Going from sh to Perl,
>we can have a sh syntax error on the second line, but going the other
>way doesn't afford us this luxury.

Just put a valid #! line at the start of the script.  Perl
itself will look at that first line, and if the word "perl"
does not appear on that #! line, perl will automagically
invoke the interpreter named there.

Quote:> why does that : at the beginning of the line work? Null line label?

I believe so.

                --Ken Pizzini