Reputation: 653
I do file transfer using rsync from a server where the files/directories have space in their name. Using single quote, I escape the space and this works
rsync -svaz --progress '[email protected]:/folder with space' '/downloads'
I am trying to write a bash script for the same but with no success, according to this thread, one can escape single quote by place it under a double quote. The following looks good
#!/bin/bash
read -e -p "source path: " SOURCEPATH
read -e -p "destination path: " DESPATH
echo "rsync -svaz --progress" "'""$SOURCEPATH""'" "'""$DESPATH""'"
But it doesn't work
#!/bin/bash
read -e -p "source path: " SOURCEPATH
read -e -p "destination path: " DESPATH
rsync -svaz --progress "'""$SOURCEPATH""'" "'""$DESPATH""'"
Upvotes: 1
Views: 1400
Reputation: 830
For escaping space in bash you need to use \
its a backslash followed by a space.
If you are reading the input from other source then simply putting a quote (either single or double) will work.
rsync -svaz --progress "$SOURCEPATH" "$DESPATH"
Note: If you are already using escape character for space while reading your input then you must use double quotes.
Upvotes: 1
Reputation: 531055
You're overquoting. Simply quoting the parameter expansion ensures that the exact value, spaces and all, are passed as a single argument to rsync
:
rsync -svaz --progress "$SOURCEPATH" "$DESPATH"
The single quotes in your original example aren't passed to rsync
; they are removed by the shell before passing the enclosed string as an argument to rsync
.
Upvotes: 0