> David Parker wrote:
> > Hi. I have a perl script that calls various programs. I would like to be
> able to verify that a given program is being called from the right place -
> what I would use "whence" for in the korn shell.
> >
> > I tried
> >
> > $path = `whence $cmdname`;
> >
> > but I don't get anything in $path. I'm undoubtedly missing something -
> I'm a beginner!
> >
> > Thanks in advance for any clues....
>
> There's no 'whence' command in ksh that I know of... I think you want
> 'which'
>
> -- Brett
> http://www.chapelperilous.net/
I recently asked this question myself on another "builtin" ksh command.
Steve, a regular contributer to this list told me the reason why my 'set'
would not work:
=== begin cut ======================================================
Actually, the shell isn't involved at all. Since there are no shell
metacharacters in the string "set", perl tries to exec "set" directly,
using the C library function execvp(), which uses $PATH.
$ strace -f perl -e 'qx(set)' 2>&1 |grep exec
execve("/usr/bin/perl", ["perl", "-e", "qx(set)"], [/* 22 vars */]) = 0
[pid 10527] execve("/bin/set", ["set"], [/* 22 vars */]) = -1 ENOENT
[pid 10527] execve("/usr/bin/set", ["set"], [/* 22 vars */]) = -1 ENOENT
[pid 10527] execve("/usr/X11R6/bin/set", ["set"], [/* 22 vars */]) = -1
ENOENT
[pid 10527] execve("/opt/bin/set", ["set"], [/* 22 vars */]) = -1 ENOENT
If you add a shell metacharacter, then perl will use the shell:
$ strace -f perl -e 'qx(set;)' 2>&1 |grep exec
execve("/usr/bin/perl", ["perl", "-e", "qx(set;)"], [/* 22 vars */]) = 0
[pid 10594] execve("/bin/sh", ["sh", "-c", "set;"], [/* 22 vars */]) = 0
The same thing goes for system(), which is where this subtlety
is documented.
$ perldoc -f system
=== end cut ========================================================
So, in order to force the shell to be called using a builtin such as "whence"
or "set", simply add a ';' to the end of your string:
#!/bin/perl
use strict;
use warnings;
my $cmdname = "date";
my $path = `whence $cmdname;`; # note the embedded ';'
print "path - $path\n";
And BTW, "which" checks your path only... "whence" checks the to see if the
command is a builtin, a function, an alias (and finally) the path. "which"
only checks the path....
-Jeff
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]