Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have the following line in a script for moving some directories to a new disk.: {`tar -cf - $_ | (cd $new_disk; tar -xBpf -)`; Unfortunately it seems the line is given to /bin/sh which does not understand it. Is there some way to force Perl to use a different shell for stuff between ` `?

Replies are listed 'Best First'.
Re: shell problem
by kilinrax (Deacon) on Sep 27, 2000 at 18:11 UTC
    This might not be the best way, but you could pipe it into a different shell.
    #!/usr/bin/perl -w use strict; open BASH, "|/bin/bash"; print BASH "tar -cf - $_ | (cd $new_disk; tar -xBpf -)"; close BASH;
Re: shell problem
by jptxs (Curate) on Sep 27, 2000 at 18:14 UTC

    You could try making the command:

    `ksh -c "tar -cf - $_ | (cd $new_disk; tar -xBpf -)"`

    most shells will take '-c' and use whatever is in the arg as the command they should execute. the shell will lauch, execute what's in '-c' and exit. try "man ksh" or whatever shell you'd like to use to be sure it takes the '-c' arg.

    10 to 1 some other monk can give you a better perl solution :) but this answers the question ;)

    -- I'm a solipsist, and so is everyone else. (think about it)

Re (tilly) 1: shell problem
by tilly (Archbishop) on Sep 27, 2000 at 18:33 UTC
    Have you looked at Archive::Tar?

    Also for problems like this it can be very nice to open on pipes and hook them up within Perl.

RE: shell problem
by merlyn (Sage) on Sep 27, 2000 at 19:26 UTC
    That line looks perfectly fine as a shell command. Perhaps $_ ends in a newline, or $new_disk is not in the format that you expect. Try changing the system operator to a simple print to ensure that the command line you are handing the shell is what you think it is.

    -- Randal L. Schwartz, Perl hacker

      This also looks like something that might be run in a cron. If so you may want to check environment and path as well.