77461

echo nested quotation marks in tcsh

Question:

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

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

Note the nested ' and " and also the : and ; that must be there.

The : and ; require the whole string to be surrounded by quotation marks. However, if I do that, I have trouble escaping the quotation marks.

The command is:

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

How can I escape the quotation marks around bar bar bar so that they get printed correctly?

Answer1:

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

or this:

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

These should work for the simple example you gave, but may not help for what you're actually trying to do... Quoting in tcsh always annoyed me, especially when trying to define aliases with a mix of back-ticks, quotes, and double-qutes.

Be warned that the second form works for echo, but it actually creates three separate arguments on the command line, which are (after interpreting the escape sequences):

<ul><li>bla bla bla 'foo foo foo "bar</li> <li>bar</li> <li>bar"': etc etc;</li> </ul>

The first form is the one you should use.

Recommend

  • Philosophy of scroll bars [duplicate]
  • In PHP getting “Class 'PDO' not found” error while trying to connect to Oracle DB
  • The TypeScript compiler couldn't be found
  • Cannot replace default icon in android studio
  • Excel formula to match multiple dates across 2 columns, returning Yes or No
  • Create Variable In Oracle
  • How to read XML file in c#?
  • How can I prevent page-break in CFDocument from occuring in middle of content?
  • Angular 2, Adding calc() as inline style. Unsafe interpolation using parentheses
  • ScalaTest v3: why require to implement convertToLegacyEqualizer
  • SailsJS user access levels and roles
  • How to open my facebook page in facebook app from button click of an android app [duplicate]
  • c# split string with long space or tabs
  • How can I control the size of the help window using System.Windows.Forms.Help.ShowHelp()?
  • How do I convert a complex json object to CLR object with json.net?
  • Variable amount of columns returned in mysqli prepared statement
  • .Net how to set IsReadOnly for a property for a usercontrol
  • Multiple custom authentication with spring security
  • Is there a function to calculate the difference between two times and display a relative result?
  • How to send binary with spring boot websocket?
  • Display standard razor/mvc 3 validation messages displayed in another language
  • How do I get the standard Vim FTP command to work?
  • Can't access web service when connected to the network :: HTTP 407
  • Octave code for gradient descent using vectorization not updating cost function correctly
  • Immutability and synchronization in Java
  • async GET request with body from browser
  • I need a PHP mySQL Login script that directs user to specific URL based on username and password
  • Sample deviceQuery cuda program
  • All Event listing on specified date in Google Calender api (V3) in java?
  • When to use the tag in the head and body section of a html page? [duplicate]
  • How to define something in JavaScript [closed]
  • Create an average of multiple excel chart without the data source
  • Neo4j…how to get a visual representation of my data?
  • Bitrate JWplayer
  • Accessing Arguments, Workflow Variables from custom activities
  • Running R's aov() mixed effects model from Python using rpy2
  • Access to a Matlab gui from the web