Escaping double quotes in expect script

expect, perl

Solution

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.

Problem

``` #!/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 root@10.xx.xx.xx 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

Original source