Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Finding out how you were called...

by rchiav (Deacon)
on Aug 06, 2001 at 23:41 UTC ( [id://102572]=note: print w/replies, xml ) Need Help??


in reply to Finding out how you were called...

$0 stores the name that the program was run as..

Either I completely misread the question or you added the bit about $0 after I wrote this :)

$0 (for me, on RH 7.1) contains the full path even if the script is in the path. The only time it doesn't is if I specify a relative path from the command line. An option could be to check, if it doesn't match the full path, if $0 and the pwd eq what you're looking for.

Rich

Replies are listed 'Best First'.
Re: Re: Finding out how you were called...
by suaveant (Parson) on Aug 06, 2001 at 23:53 UTC
    Since I can't edit SOPW posts... :)

    what I need is the command that was called, including the directory of it...

                    - Ant
                    - Some of my best work - Fish Dinner

Re: Re: Finding out how you were called...
by suaveant (Parson) on Aug 06, 2001 at 23:55 UTC
    I assume that $0 is set by the shell, not by the OS... I have RH 7.1 with bash and I get exactly what was typed to run the command... i.e. foo ./foo /usr/bin/foo etc...

                    - Ant
                    - Some of my best work - Fish Dinner

      wierd.. I have RH 7.1 with bash (perl 5.61). Here's my test
      #!/usr/bin/perl -w print " I was called as $0\n";
      results as follows. tt is the original file. rr is a symlink in /usr/local/bin
      [xxxx@yyy:/home/xxxx]$ tt I was called as ./tt [xxxx@yyy:/home/xxxx]$ rr I was called as /usr/local/bin/rr [xxxx@yyy:/home/xxxx]$
        My bad... I was assuming perl's $0 and c's argv[0] were the same, which they are not... $0 does have exactly what I want, thanks...

                        - Ant
                        - Some of my best work - Fish Dinner

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found