User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: [bash] scp in script with ~ expansion and shell escape

Sun Aug 18, 2013 4:44 pm

Can we see the output from your script also ?

Have you tried:

Code: Select all

REMOTE="\"/tmp/remote file.jpg\""

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: [bash] scp in script with ~ expansion and shell escape

Sun Aug 18, 2013 4:57 pm

http://linux.die.net/Bash-Beginners-Gui ... 03_03.html

Maybe using singlequotes together with escaping the spaces is a solution.

Spaces in filenames are the source of all evil anyway, avoid at all cost.

User avatar
jojopi
Posts: 3274
Joined: Tue Oct 11, 2011 8:38 pm

Re: [bash] scp in script with ~ expansion and shell escape

Sun Aug 18, 2013 6:36 pm

ednl wrote:LOCAL="~/Desktop/local file.jpg"
Tilde expansion is inhibited by double quotes. You can write LOCAL=~/"Desktop/local file.jpg", or LOCAL="$HOME/Desktop/local file.jpg".
scp host:$QQREMOTE $QLOCAL
Both variables have embedded spaces. You need them to be passed to scp as two arguments, and not four. This can only be achieved by putting the expansions inside double quotes, not by inserting quotes or backslashes into the variables' contents. Using quotes protects the arguments from the local shell, so only the remote argument needs extra protection:

Code: Select all

scp host:"$QREMOTE" "$LOCAL"
(Word splitting of variable expansions is practically never desirable, so you should practically always put double quotes around variables.)

Return to “Other programming languages”