Turning Quoatation off - rsync from bash

I usually work on it fast enough, but it's a headache.

I have a shell script that loads some information about where to connect and how from a text file, this is done using a read command. It works. It stores the arguments to be sent to RSync in a variable call to $ rsyncargs.

I want to use RSync arg -e, which is used to transfer details to ssh, in my case the port number:

rsync -avz -e "ssh -p 222" dir/ bob@server.com:dir/

the line in the text file looks like this:

-e "ssh -p 222"

The bash line should look something like this:

rsync -avz $rsyncargs $src $dst

it all works, except that the quotes are messy, and I end up with

sending incremental file list
rsync: link_stat "/dir/to/shell/script/222"" failed: No such file or directory (2)

, . ( ​​..), , , ( ) .

( , ssh )

+3
4

ssh:

>cat ~/.ssh/config
Host shortName
   Hostname [actual url or ip]
   User otherUserName
   Port 22
   ForwardAgent yes
   ForwardX11 yes
+1

, :

rsyncargs="ssh -p 222"

rsync -avz -e $rsyncargs $src $dst

, :

rsyncargs='-e "ssh -p 222"'

, , , .

+1

I agree with @Dennis Williamson, and the answer is that you probably need to quote less, no more, i.e.:

less_quote_rsyncargs=$(echo $rsyncargs)
rsync -avz $less_quote_rsyncargs $src $dst
0
source

I had this problem: I found that it works, no quotes in the outer shell option and avoid the spaces it needs:

rsync -azvxSe ssh \ -p $ PORT $ src $ SERVER: / $ dst

I also have no place between -p and $ PORT, which I think will completely solve the OP problem.

0
source

Source: https://habr.com/ru/post/1762289/


All Articles