Surely I'm missing something simple, but this is driving me nuts. I'm trying to SCP a remote file to the current local directory. The remote path has spaces in it. I need this to run in a script and put the path into a variable, because it's being read from a file.
Problem is, no matter how I try to escape it, I'm still getting a "File or Directory not found" error. I put the -v option on the scp command, and the command it's sending over works if I copy and paste it, but when I have the variable in there, it blows up.
Note that it works fine if I write out the path, but breaks when I try to put the path into a variable. There's lots of similar questions for just escaping a hard coded string, but I couldn't find anything for using variables with spaces in the filepath.
Path to file is:
/home/myUser/databases/SONIC BOATS LTD./database-1.11-2019-12-30-09-40.zip
When running scp verbose, the line sending command prints the following:
scp -f /home/myUser/databases/SONIC\\ BOATS\\ LTD./database-1.11-2019-12-30-09-40.zip .
If I paste that line into my script and run it, then it works. So why isn't it working when it's running in the script with the variables?
while read DB_ARC_FILENAME
do
# Escape spaces in the files name
ESC_DB_ARC_FILENAME=${DB_ARC_FILENAME//\ /\\\ }
# Copy the database file to the local system
scp -v [email protected]:"$ESC_DB_ARC_FILENAME" .
...
done < uploadedDatabaseFileList
Here's the output I'm getting when I run it:
debug1: Sending command: scp -v -f /home/myUser/databases/SONIC\\ BOATS\\ LRD./database-1.11-2019-12-30-09-40.zip
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
: No such file or directoryer/databases/SONIC BOATS LTD./database-1.11-2019-12-30-09-40.zip
debug1: channel 0: free: client-session, nchannels 1
: No such file or directoryes/SONIC BOATS LTD./database-1.11-2019-12-30-09-40.zip
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
Transferred: sent 2836, received 2704 bytes, in 0.8 seconds
Bytes per second: sent 3678.9, received 3507.7
debug1: Exit status 1