A
A
Andrew2020-01-13 19:40:01
bash
Andrew, 2020-01-13 19:40:01

How to properly use escaping in bash?

Hello
I'm tormenting the expect script to automate the telnet action.
This script works, although not perfectly:

#!/usr/bin/expect

spawn telnet-ssl
expect ">"
send "set crlf\r";
expect ">"
send "open  192.168.1.201\r";
expect ''
send  "cd online\r";
expect ''
send "nc 216.146.43.71 80 > 192.168.1.201.ext.ip\r";
expect ''
send "tftp -s -l 192.168.1.201.ext.ip  192.168.1.2\r";
expect ''

If you expand the command nc 216.146.43.71 80 and try it like this:
nc 216.146.43.71 80 | grep -E -o '([0-9]{1,3}[\.]){3}[0-9]{1,3}' > 192.168.1.201.ext.ip

bash swears.
As I understand it, you need to escape quotes inside quotes, right?
Help with syntax!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Germanjon, 2020-01-14
@Germanjon

The point is that quotes (by default) interpret special characters $ \ ` . That is, the backslash in your example is treated as a special character.
Apostrophes (single quotes) pass the string unchanged, i.e. $ \ ` is treated as a regular character in text.
It makes sense to replace quotes in send with apostrophes and "play" with it.
Linux is not at hand, so I can not accurately specify the working version of the line.

L
Lev Zabudkin, 2020-01-15
@zabudkin

Unfortunately, I didn't find an answer.
Sorry.
And this doesn't work?
nc 216.146.43.71 80 | egrep '([0-9]{1,3}[\.]){3}[0-9]{1,3}'
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question