in reply to one liner in script

Can you please specify what the script should do, according to your intentions?

Replies are listed 'Best First'.
Re^2: one liner in script
by Anonymous Monk on Apr 12, 2010 at 14:20 UTC
    Actually I have a much larger perl script where I run a bunch of commands from the command line in between back tacs like
    $line=`cmd 1; cmd 2 ; cmd 3 .... cmd n `;
    Now for one of the commands I have to run it for only 4 secs. Now the only way I could come up with is like this : alarm() { /bin/perl -e 'alarm shift; exec @ARGV' "$@"; } ;alarm 4 'cmd 4 ' Now when I try to put that in a perl script between back tacs it doesnt work. This code doesnt work.
    $line=`cmd 1; cmd 2 ; cmd 3 ;alarm() { /bin/perl -e 'alarm shift; exec + @ARGV' "$@"; } ;alarm 4 'cmd 4 '.... cmd n `;
    Is there anyway I can make the cmd 4 run for 4 secs only.
      This code works for me:
      $line=` cmd 1 cmd 2 cmd 3 alarm () { /usr/bin/perl -e ' alarm shift; exec \@ARGV;' -- "\$@" } alarm 4 cmd 4 cmd n `; print "$line";
      The differences are:
      1. path to perl (might be different on your system)
      2. escaping the @ sign
      3. escaping the $ sign
      4. Update: the -- separator
        Ahh xlente... Thank you for helping me . I will put this in the script and check . It should work now.