0

When a file name contains spaces ,the file name need escape two times in scp command.
I can get file "somesoft someversion.apk" from remote ip address into my local "tmp" directory:

scp user@ip_address:/share/"somesoft\\ someversion.apk"  /tmp

It works fine.Now i want to use a var name to refer to the file "somesoft someversion.apk".

fname="somesoft someversion.apk"
scp user@ip_address:/share/"$fname"  /tmp

The var can't be parsed properly in scp command:

scp: /share/somesoft: No such file or directory
scp: someversion.apk: No such file or directory

How to expand variable whose value contains space properly in scp command?
Now here is the real case,scp works fine with two time escapes:

enter image description here

Now to set a var and assign value with it,then scp: enter image description here

"'$fname'" have no magic effect in this case.

showkey
  • 482
  • 42
  • 140
  • 295

1 Answers1

2

You have to shell quote it.

fname="somesoft someversion.apk"
scp user@ip_address:/share/"$(printf "%q" "$fname")"  /tmp
KamilCuk
  • 120,984
  • 8
  • 59
  • 111