问题
#!/opt/sfw/bin/expect --
spawn telnet -e ! [lindex $argv 0]
expect "<"
send "ACT-USER::ABCDEFG:123::\"ABCD\";"
Above is not working giving error due to double quote inside a double quote
Error:
spawn telnet -e !
Telnet escape character is '!'.
invalid flags
send: spawn id exp7 not open
while executing
"send "ACT-USER::ABCDEFG:123::'\"ABCD\"';""
(file "./get-amp-pms.sh" line 4)
回答1:
Use curly braces instead of the double quotes for the send, as follows:
send {ACT-USER::ABCDEFG:123::"ABCD";}
回答2:
The error is unrelated to the double-quoting; the spawned process is exiting on an error before the command string is being sent.
expect is tcl, so tcl quoting mechanisms work. Sending a string with double quotes can be done by escaping the quoted with backslashes, or using braces:
send "message with \"double quotes\""
send {message with "double quotes"}
回答3:
Not sure But we can use single quote in few commands like(sed) to overcome this issue and freely use double quote inside single quote without hampering the functionality.So try using the parameters enclosed in single quote(Example : send 'paramters' )to execute it
来源:https://stackoverflow.com/questions/34586662/want-to-use-double-quote-inside-a-double-quote