Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Re: Perl on a Mac

Reply
Thread Tools

Re: Perl on a Mac

 
 
Jürgen Exner
Guest
Posts: n/a
 
      04-22-2012
Torsten Jørgensen <(E-Mail Removed)> wrote:
>Does it understand #!/usr/bin/perl.


No, it doesn't. It doesn't on any OS because the shebang line is a
function of the shell, not of Perl. Perl doesn't care about the shebang
line(*).

>Can the Terminal run shell scripts.


Why not?

*: actually there are hacks for some OSs where Perl will parse arguments
from the shebang line because the command interpreter on those OSs does
not recognize the shebang line.

jue
 
Reply With Quote
 
 
 
 
Tim McDaniel
Guest
Posts: n/a
 
      04-22-2012
In article <(E-Mail Removed)>,
J_rgen Exner <(E-Mail Removed)> wrote:
>Torsten J_rgensen <(E-Mail Removed)> wrote:
>>Does it understand #!/usr/bin/perl.

>
>No, it doesn't. It doesn't on any OS because the shebang line is a
>function of the shell, not of Perl.


That happens not to be the case. In UNIX and UNIX derivatives, the
system detects when the first two characters of the file are "#!".
"man 2 execve" on Ubuntu (one version back), where "2" means it's a
system call:

execve() executes the program pointed to by filename. filename
must be either a binary executable, or a script starting with a
line of the form:

#! interpreter [optional-arg]

For details of the latter case, see "Interpreter scripts" below.

<http://kernel.org/doc/man-pages/online/pages/man2/execve.2.html> has
a Linux man page, including implementations details and how different
systems differ in their implementations of it.

Below is an example program showing a binary (100, compiled from
100.c) executing a script (100.cat) without any shell being involved.

In the 1980s, if you were using csh and a file began with "#" (not
"#!), then csh would interpret it as a csh script instead of calling
the kernel. That is no longer the case on current Linux or NetBSD
5.1.2, the two systems I can check conveniently. There, the correct
interpreter (/bin/cat, if I re-use the example script below) gets
called, though I can't easily test to see whether csh caused it or the
kernel.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~

$ cat 100.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
char *newargv[] = { "100.cat", (char *) NULL };
char *newenviron[] = { (char *) NULL };

execve("100.cat", newargv, newenviron);
perror("execve"); /* execve() only returns on error */
exit(EXIT_FAILURE);
}
$ cat 100.cat
#! /bin/cat
Hello, world!
$ cc -o 100 100.c
$ chmod u+x 100.cat
$ ./100
#! /bin/cat
Hello, world!

 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      04-22-2012
On 2012-04-22 06:08, Torsten Jørgensen wrote:

> And by the way, keep your inuendo to yourself, it is insulting.


A big lesson that many usenet users still need to learn, again and
again, is that you are what you read.
If you feel that something you read, annoys you, then realize that you
were already annoyed before you started reading it.

In am not interested in people that show behavior like Torsten just did,
with the exception of close family. For usenet that is easy to express,
I just create a filter and he's being plonked. I don't actually have a
plonk sound for every plonk that my filters do, I prefer the silence.

--
Ruud

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      04-22-2012
Torsten Jørgensen <(E-Mail Removed)> wrote:
>On 2012-04-22 03:51:59 +0000, Jürgen Exner said:
>
>> Torsten Jørgensen <(E-Mail Removed)> wrote:
>>> Does it understand #!/usr/bin/perl.

>>
>> No, it doesn't. It doesn't on any OS because the shebang line is a
>> function of the shell, not of Perl. Perl doesn't care about the shebang
>> line(*).

>
>I know, I meant the shell...


Ok.
Sorry, I can only read what you are writing, not what you are thinking.

>>> Can the Terminal run shell scripts.

>>
>> Why not?

>
>Except that it comes out with -bash: seek.pl: command not found
>when I try to run this:
>
>#!/usr/bin/perl
>print "Hello World";


Then I would guess there is no executable program named perl at
/usr/bin. Maybe it is not installed? Maybe it is in a different
location? Maybe access rights are incorrect?

>> *: actually there are hacks for some OSs where Perl will parse arguments
>> from the shebang line because the command interpreter on those OSs does
>> not recognize the shebang line.

>
>But OSX Lion does...


That's fine. I was merely mentioning that on certain OSs there are
exceptions to the standard behaviour of Perl.

>And by the way, keep your inuendo to yourself, it is insulting.


-v, please?

jue
 
Reply With Quote
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      04-22-2012
Torsten Jørgensen <(E-Mail Removed)> wrote:
> On 2012-04-22 03:51:59 +0000, Jürgen Exner said:
> > Torsten Jørgensen <(E-Mail Removed)> wrote:
> >> Does it understand #!/usr/bin/perl.

> >
> > No, it doesn't. It doesn't on any OS because the shebang line is a
> > function of the shell, not of Perl. Perl doesn't care about the shebang
> > line(*).


> I know, I meant the shell...


> >> Can the Terminal run shell scripts.

> >
> > Why not?


> Except that it comes out with -bash: seek.pl: command not found
> when I try to run this:


I've no experience with Macs but I heard that their OS is based
on BSD. And if that's the case you may have to put "./" in front
of the scripts name when you try to run it from the shell, i.e.
use

../seek.pl

since the current directory isn't necessarily in the paths the
shell looks for programs in. And, of course, to get it to work,
you also need the "execute" flag set for the script, i.e. you
may have to set the execute permission with a command like

chmod +x seek.pl

Without the execute flag being set the "#!" won't do anything.

Regards, Jens
--
\ Jens Thoms Toerring ___ http://www.velocityreviews.com/forums/(E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      04-22-2012
>>>>> "BM" == Ben Morrow <(E-Mail Removed)> writes:

BM> Perl always parses arguments from the #! line, on all OSs. Even on OSs
BM> which understand #!, the kernel always passes the whole of the rest of
BM> that line (up to a fixed limit) as one argument, and on some OSs that
BM> limit was rather small. Perl goes to some trouble to sort out the
BM> resulting mess so you can apparently put several arguments on the #!
BM> line and it will Just Work.

perl gets the #! just by reading the source file it is passed. it
doesn't need any help from the kernel to see it all.

uri
 
Reply With Quote
 
Tim McDaniel
Guest
Posts: n/a
 
      04-22-2012
In article <(E-Mail Removed)>,
J_rgen Exner <(E-Mail Removed)> wrote:
>Torsten J_rgensen <(E-Mail Removed)> wrote:
>>Except that it comes out with -bash: seek.pl: command not found
>>when I try to run this:
>>
>>#!/usr/bin/perl
>>print "Hello World";

>
>Then I would guess there is no executable program named perl at
>/usr/bin. Maybe it is not installed? Maybe it is in a different
>location? Maybe access rights are incorrect?


"type perl" or "which perl" may say where it is. For example, on my
ISP,

$ type -a perl
perl is /usr/local/bin/perl

But other systems may differ.

--
Tim McDaniel, (E-Mail Removed)
 
Reply With Quote
 
Tim McDaniel
Guest
Posts: n/a
 
      04-22-2012
In article <(E-Mail Removed)>,
Ben Morrow <(E-Mail Removed)> wrote:
>
>Quoth (E-Mail Removed):
>> In article <(E-Mail Removed)>,
>> J_rgen Exner <(E-Mail Removed)> wrote:
>> >Torsten J_rgensen <(E-Mail Removed)> wrote:
>> >>Does it understand #!/usr/bin/perl.
>> >
>> >No, it doesn't. It doesn't on any OS because the shebang line is a
>> >function of the shell, not of Perl.

>>
>> That happens not to be the case. In UNIX and UNIX derivatives,

>
>The kernel implementation of #! is a BSD thing, though I believe it
>made its way into all the SysVs eventually.


Regardless of the history, I have not heard of any extant current UNIX
derivative that doesn't have it. Linux certainly does.

And to quibble: technically no, but effectively yes.

http://www.in-ulm.de/~mascheck/various/shebang/
The #! magic, details about the shebang/hash-bang mechanism on
various Unix flavours
2011-12-27
has a history that says it was done at Bell Labs after Version 7,
announced by Dennis Richie, but BSD 4 (not BSD 2) was the first wide
distribution to pick it up. "Among the public releases from Bell
Labs, #! was not added until SVR4 ('8 according to a TUHS list
discussion. System III and SVR1 definitely had not implemented it,
yet."

It links to http://homepages.cwi.nl/~aeb/std/hashexclam.html
#! - the Unix truth as far as I know it.
Andries Brouwer, (E-Mail Removed)
v1.2, 2002-12-05
, which gives more details about changes and implementations.

--
Tim McDaniel, (E-Mail Removed)
 
Reply With Quote
 
Tim McDaniel
Guest
Posts: n/a
 
      04-22-2012
In article <(E-Mail Removed)>,
Ben Morrow <(E-Mail Removed)> wrote:
>Even on OSs which understand #!, the kernel always passes the whole
>of the rest of that line (up to a fixed limit) as one argument


http://homepages.cwi.nl/~aeb/std/has...m-1.html#ss1.3 says that
there's lots of variations on that, though I find it confusing because
he uses the present tense to refer to long-obsolete UNIX variations.

- Most systems do that.
Some split on whitespace and pass multiple arguments.
Some split on whitespace and ignore all but the first.
One line of development treated # as a comment character, but later
yanked it out.
- Systems have various limits, but "BSD/OS 4.2 does not truncate".
- Some delete trailing whitespace, some do not.
- Some systems (Linux) keep trailing \r as part of the argument.
Others (Solaris) strip it too.
- Systems differ on what arg0 that they will pass.
- Some systems do not allow a script to be on the #! line.

In short, to go by that, you can portably depend on 0 or 1 argument
if there's no whitespace in it or after it, no \r, and less than 80
bytes on modern systems.

--
Tim McDaniel, (E-Mail Removed)
 
Reply With Quote
 
Hans Mulder
Guest
Posts: n/a
 
      04-22-2012
On 22/04/12 19:27:38, Uri Guttman wrote:
>>>>>> "BM" == Ben Morrow <(E-Mail Removed)> writes:

>
> BM> Perl always parses arguments from the #! line, on all OSs. Even on OSs
> BM> which understand #!, the kernel always passes the whole of the rest of
> BM> that line (up to a fixed limit) as one argument, and on some OSs that
> BM> limit was rather small. Perl goes to some trouble to sort out the
> BM> resulting mess so you can apparently put several arguments on the #!
> BM> line and it will Just Work.


> perl gets the #! just by reading the source file it is passed. it
> doesn't need any help from the kernel to see it all.


One exception to this, is the '-T' switch. If you let the kernel process
the shebang line, then it will pass the -T on the command line and perl
will run in taint mode. It perl only finds the -T when it parses the
first line of the source file, then it's too late and perl will abort:

$ cat demo.pl
#!/usr/bin/perl -T
print "Hello, world\n";
$ ./demo.pl
Hello, world
$ perl demo.pl
"-T" is on the #! line, it must also be used on the command line at
demo.pl line 1.
$ perl -T demo.pl
Hello, world
$


-- HansM
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 02-27-2011 11:00 PM
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 02-03-2011 11:00 AM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 01-23-2011 05:00 AM
Activestate Perl and original Perl both on Mac OS Tiger Jake Wiley Perl Misc 14 06-16-2005 10:47 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments