title: Escaping special characters in bash variables
body: <p>I'm trying to read a file containing filepaths line by line and scp the files to another server, but because of certain characters in the filenames like '(', ')', '&amp;' etc. I need to escape the input:</p>
  
  <p><strong>input.txt</strong>:</p>
  
  <pre><code>/folder1/folderA/filename+(oh+how+nice,+parantheses)
  </code></pre>
  
  <p><strong>script.sh</strong>:</p>
  
  <pre><code>#!/bin/sh
  
  promote_to=random.server.com
  dev_catalog=/folderX/
  uat_catalog=/folderY/
  
  while read line
  do
  uat_path=$(echo "$uat_catalog$line" | sed -e "s/(/\\\(/g" | sed -e "s/)/\\\)/g")
  dev_path=$(echo "$dev_catalog$line" | sed -e "s/(/\\\(/g" | sed -e "s/)/\\\)/g")
  
  scp $dev_path user@$promote_to:$uat_path
  scp $dev_path".atr" user@$promote_to:$uat_path".atr"
  done &lt; "input.txt"
  </code></pre>
  
  <p><strong>Output</strong>:</p>
  
  <pre><code>-bash: /folder1/folderA/filename+(oh+how+nice,+parantheses): No such file or directory
  -bash: /folder1/folderA/filename+(oh+how+nice,+parantheses): No such file or directory
  usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
                 [-l limit] [-o ssh_option] [-P port] [-S program]
                 [[user@]host1:]file1 [...] [[user@]host2:]file2
  ssh: random.server.com: Name or service not known
  lost connection
  </code></pre>
  
  <p>Any kind of help is appreciated.</p>