I'm trying to mirror copy the whole directory from one cluster to another cluster right now. But it fails when there is a space in the name and I can't figure out how to solve this problem because it seems scp thinks I'm copying multiple files. I'm using a variable to flag the path that I need so it seems it would not be easily solved by adding a back slash.
This is the code that I'm using:
if ssh user@ip -i key test -d "'$current_dir'"; then echo "Directory exists. Ready to copy $dir_name." scp -i key -r "$current_dir/$dir_name" user@$ip:"$current_dir/$dir_name" else echo Directory doesn\'t exist. Making a new directory. ssh user@$ip -i key mkdir "'$current_dir'" scp -i key -r "$current_dir/$dir_name" user@$ip:"$current_dir/$dir_name" fi I have tried single quote, double quotes and single quote with double quotes, but none of them works. Can anyone help me solve it? By the way, the mkdir statement in the code works.
$current_dir? What error are you getting exactly?$current_diris the variable stores the path returned frompwd. And the error says scp ambiguous target.$current_dirthat fails. You can useset -xto get the shell to print the exact command it will run out when it runs it.set -xand exact error output. You may very well need to escape or extra-quote the spaces in the filename so they make it through to scp but without seeing what is happening I can't be sure I even know what the problem is.