title: Dealing with variables and new lines, and quoting in a bash script
body: <p>I would like to automate the following svn command. Note this command produces the desired results on my system - Ubuntu 10.04, svn 1.6.6, bash shell, when issued from the command line:</p>
  <pre><code>svn ci -m $'Added new File: newFile.txt\nOrig loc: /etc/networking/newFile.txt' /home/user/svnDir/newFile.txt
  </code></pre>
  <p>I would like to run that command in a bash script, assuming that the original full path to the file is contained in the variable $oFileFull, and the filename is in $oFileName. The script is executed from the svn directory. I need to allow for the possibility that the file name and or path contain spaces.</p>
  <p>so the line inside my shel script might look like:</p>
  <pre><code>svn ci -m$'Added new file: ${oFileName}\nOrig loc: ${oFileFull}' ${oFileName}
  </code></pre>
  <p>But I want the variables (which may contain spaces) expanded before the command is executed, and I cannot figure out how to do this while enclosing the svn comment in single quotes which is necessary in order to get the new line in the subversion comment log. I am pulling my hair out trying to figure out how to properly quote and assemble this command. Any help appreciated.</p>
  <hr />
  <ul>
  <li>The following was posted as an answer, but should have been an edit.</li>
  </ul>
  <p><a href="https://stackoverflow.com/users/26428/dennis-williamson">@Dennis</a>:</p>
  <p>Wow, this is hard to wrap my head around, I'd love it if someone could point me towards an online resource that explains this clearly and concisely. The ones I have found have not cleared it up for me.</p>
  <p>My latest source of confusion is the following:</p>
  <pre><code>#!/bin/bash
  nl=$'\n'
  msg=&quot;Line 1${nl}Line 2&quot;
  echo $msg        # ouput = Line 1 Line 2
  echo -e $msg     # ouput = Line 1 Line 2
  echo &quot;$msg&quot;      # output = Line 1
                   # Line 2
  </code></pre>
  <p>What I'm attempting to illustrate is that having the double quotes around the variable $msg splits the output into two lines, without the double quotes, even with the -e switch, there is no new line.</p>
  <p>I don't get why the double quotes are necessary - why isn't the $nl variable expanded when it is assigned as part of the msg variable?</p>
  <p>I hope I'm not committing a StackOverflow faux pas by answering my own question. And in fact, I am not really providing an answer, but merely a response to your comment. I cannot format a comment as necessary.</p>