Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: Specifying a shell for use with Backticks

by bluto (Curate)
on Apr 12, 2006 at 15:29 UTC ( #542859=note: print w/replies, xml ) Need Help??

in reply to Re: Specifying a shell for use with Backticks
in thread Specifying a shell for use with Backticks

If you really can't get backticks to use a reasonable shell, perhaps you can trick it. For example in ksh, you can do something like this...

my $output = `PATH=$ENV{PATH} command arg1 arg2 argn`;

... which sets PATH just for the command. Just be careful you know what is in $ENV{PATH} (e.g. no spaces; not user supplied). I don't know if this syntax will work for csh also, so perhaps something ugly like...

my $output = `setenv PATH "$ENV{PATH}"; command arg1 arg2 argn`;

An alternative, if you are only worred about the PATH, might be to supply a fullpath to backticks (i.e. dont give the shell a chance to locate it - just tell it)...

my ($cp) = grep { -x $_ } map { "$_/cp" } grep { length $_ } split /:/ +, $ENV{PATH}; die "cant find cp" unless defined $cp; my $output = `$cp source dest`;

IMO these seem like band-aids for the real problem. Using csh is just unsafe, outside of an interactive shell.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2021-10-26 18:16 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (90 votes). Check out past polls.