Using a filename with spaces with scp and chmod in bash.

Posted by speciousfool on Stack Overflow See other posts from Stack Overflow or by speciousfool
Published on 2010-03-08T06:46:46Z Indexed on 2010/03/08 6:51 UTC
Read the original article Hit count: 373

Filed under:
|
|

Periodically, I like to put files in the /tmp directory of my webserver to share out. What is annoying is that I must set the permissions whenever I scp the files. Following the advice from another question I've written a script which copies the file over, sets the permissions and then prints the URL:

#!/bin/bash

scp "$1" SERVER:"/var/www/tmp/$1"
ssh SERVER chmod 644 "/var/www/tmp/$1"
echo "URL is: http://SERVER/tmp/$1"

When I replace SERVER with my actual host, everything works as expected...until I execute the script with an argument including spaces. Although I suspect the solution might be to use $@ I've not yet figured out how to get a spaced filename to work.

© Stack Overflow or respective owner

Related posts about bash

Related posts about ssh