Search code examples
bashvariablesscpquoting

SCP command with a space in the target


I would like to make a scp command with a variable for the file destination but, in the variable I have a space.

~ $ target=C:/Users/exemple/a folder with space/data
~ $ scp -r -p file.txt $USER@$IP_TARGET:${target}
space/data: No such file or directory

How can I do ?


Solution

  • I succeeded with this :

    target='"C:/Users/exemple/a folder with space/data"'
    

    Or this :

    target=\"C:/Users/exemple/a folder with space/data\"
    

    and use

    scp -r -p file.txt $USER@$IP_TARGET:"$target"