user1972031
user1972031

Reputation: 557

Escape double quote in perl

When I passed a variable $local_ntwk_ao_vpn ("X0 Subnet") into a perl script, it only took "X0" and lost "Subnet" part. I tried to escape double-quotes as below, but still didn't work. Any help is greatly appreciated.


#!/usr/bin/perl
use Expect;
#Assume the first 20 args are OK
my $local_ntwk_ao_vpn    = $ARGV[20];   # <-----"X0 Subnet"

# Telnet into the remote firewall
my $expect = Expect->new();
$expect->spawn("telnet 10.100.100.100 6025");
$expect->send("\n");
sleep(3);
$expect->expect( 10, 'User:' );
$expect->send("aUser\n");
$expect->expect( 10, 'Password:' );
$expect->send("password\n");
$expect->expect( 5, '>' );

$expect->send("configure\n");
$expect->expect( 5, '#' );

$expect->send("vpn policy site-to-site TESTVPN\n");
$expect->expect( 5, '#' );
$expect->send("network local name \"$local_ntwk_ao_vpn\"\n");  # <-- Still doesn't work here.
$expect->expect( 5, '#' );
$expect->send("exit\n");
$expect->send("end\n");
$expect->soft_close();

Errorlog:

(edit-site-to-site[TESTVPN])# network local name "X0"
% Error encountered at '^' marker:
    network local name "X0"
                       ^^M
% Error: No matching command found.
(edit-site-to-site[TESTVPN])# exit

Desired command:

 (edit-site-to-site[TESTVPN])# network local name "X0 Subnet"

Upvotes: 0

Views: 319

Answers (1)

ikegami
ikegami

Reputation: 385655

I believe you are mistaken about $ARGV[20] containing X0 Subnet. It appears to contain only X0.

Did you use

script.pl ... X0 Subnet ...

when you should have used

script.pl ... 'X0 Subnet' ...

Upvotes: 5

Related Questions