Echo nested quotes in tcsh

I have a tcsh script that generates a text file. One of the lines in a text file:

bla bla bla 'foo foo foo "bar bar bar"': etc etc; 

Pay attention to the nested ' and " , as well as : and ; which should be there.

: and ; require the entire string to be surrounded by quotation marks. However, if I do this, it is difficult for me to escape quotes.

Command:

 echo "bla bla bla 'foo foo foo "bar bar bar"': etc etc;" >> outfile 

How can I avoid quotes around bar bar bar so that they print correctly?

+4
source share
1 answer
 echo "bla bla bla 'foo foo foo "\""bar bar bar"\""': etc etc;" 

or that:

 echo "bla bla bla 'foo foo foo "\"bar bar bar\""': etc etc;" 

They should work on the simple example that you gave, but cannot help with what you are actually trying to do ... The tcsh quote always annoyed me, especially when trying to define aliases using a combination of backticks, quotation marks, and double qutes .

We will warn you that the second form works for echo, but actually creates three separate arguments on the command line, which (after interpreting the escape sequences):

  • bla bla bla 'foo foo foo "bar
  • bar
  • bar "': etc etc.

The first form is the one you should use.

+8
source

Source: https://habr.com/ru/post/1285783/


All Articles