title: Trying to escape space in a NSString object
body: <p>I have a path that might contain spaces that I later want to pass as an argument to a shell script, running on macOS. In order for this to work I have to escape the spaces, in the same manner as bash does when I do command completion, with a backspace character.</p>
  
  <p>Example: This is a path to start with:</p>
  
  <p><code>dbHome="/Library/Application Support/MimerSQL"</code></p>
  
  <p>This is what I want to have after escaping spaces:</p>
  
  <p><code>dbHome="/Library/Application\ Support/MimerSQL"</code></p>
  
  <p>In order to do this replacement I call <code>stringByReplacingOccurrencesOfString</code> thus:</p>
  
  <p><code>dbHome = [dbHome stringByReplacingOccurrencesOfString:@" " withString:@"\ "];</code></p>
  
  <p>but that gives me a compiler warning ("Unknown escape sequence '\ '") and a resulting string that is the same as the original. I then tried to escape the backspace character thus:</p>
  
  <p><code>dbHome = [dbHome stringByReplacingOccurrencesOfString:@" " withString:@"\\ "];</code></p>
  
  <p>and that got rid of the compiler warning but it instead resulted in a totally different string than I wanted:</p>
  
  <p><code>dbHome="/Library/Application\\ Support/MimerSQL"</code></p>
  
  <p>So I am stuck. :(</p>
  
  <p>Bottom line: how can I go from "...Application Support..." to "...Application\ Support..."?</p>