in reply to Net::OpenSSH quoting problems

G'day jhuijsing,

You haven't actually asked a question, so I don't know exactly which part of this you're having difficulties with.

If you just want to know how to get from 'item 0-9 10-14' to 'item\ 0-9\ 10-14', you can do it like this:

#!/usr/bin/env perl -l use strict; use warnings; my $object = 'item 0-9 10-14'; print $object; $object =~ s/( \d+-\d+)/\\$1/g; print $object;

Output:

item 0-9 10-14 item\ 0-9\ 10-14

If you wanted something else, please specify.

-- Ken

Replies are listed 'Best First'.
Re^2: Net::OpenSSH quoting problems
by jhuijsing (Acolyte) on May 13, 2014 at 05:53 UTC
    That doesn't work
    #with the debug flag set $Net::OpenSSH::debug |= 16; $object =~ s/( \d+-\d+)/\\$1/g; $cmd = qq|blah blah $object blah blah|; ( $output, $errput ) = $ssh->capture2( $cmd ) or $logger->logdie( "bad".$ssh->error ); using the debugger x $object item 0-7 0-9 after substitution x $object item \\ 0-7\\ 0-9' # lot of stuff removed the #open_ex ...... 'blah blah item\\ 0-7\\ 0-9
    It sending a \\ not "item\ 0-7\ 0-9"
      This works for me:
      DB<5> $object = "2-4 5-12" DB<6> $object =~ s/([-\d]+)/\\$1/g DB<7> p $object \2-4 \5-12
      Or you could store the backslash in a variable and use that variable:
      DB<11> $c = '\\'; DB<12> p $c \ DB<13> $object = "2-4 5-12" DB<14> $object =~ s/([-\d]+)/$c$1/g; DB<15> p $object \2-4 \5-12
        Ok so when I use p to look the variable it look correct But, it still not right when I look at the debug from NET::OPENssh The string being sent still has the double \\ and the appliance reject this and I get an error