Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping double quotes in expect script

Tags:

perl

expect

#!/usr/bin/perl

$command = "SetBaseStationParam(\\\"PDP_ACTIVATION_REJECT\\\",0);"
system (boa.exp $command);

boa.exp script will take this command login to a linux machine and executes the script.

# /Usr/bin/expect 
set timeout 5
set arg1 [lindex 0]
spawn ssh [email protected]

expect "password:" 
send "pass\r"
expect "$" 

send "$arg1\r"
expect "$"

But this script is removing the first double quotes in the command and printing it as

output is

SetBaseStationParam(\PDP_ACTIVATION_REJECT",0);

Expected output is

SetBaseStationParam("PDP_ACTIVATION_REJECT",0);

Please let me know if there is any solution for this

like image 683
Tkills Avatar asked Dec 12 '12 07:12

Tkills


1 Answers

When you use double backslashes it escapes the backslash, so the proper way to escape a quote is \".

However, a better solution is to use qq(). It can be used with a great variety of characters as delimiter, such as | for example:

$command = qq|SetBaseStationParam("PDP_ACTIVATION_REJECT",0)|;

Or in your case, even use single quotes

$command = 'SetBaseStationParam("PDP_ACTIVATION_REJECT",0)';

You should be aware that not using

use strict;
use warnings;

Is a very bad idea indeed.

like image 66
TLP Avatar answered Sep 30 '22 00:09

TLP