Skip to content
Advertisement

Unable to pass filename with space through variable to SCP command

I am trying to set the variable $file as “Unavailable Voucher’s Report_Apr-2017.txt”. It is getting set to the variable successfully. But I am getting an error when I use this variable in a SCP command inside my script. I have tried to replace the ‘ ‘(space) with ‘ ‘(escaping space), still no use.

[***]# scp $file user@remoteserver:/path

Error be like:

Unavailable\: No such file or directory
Voucher's\: No such file or directory
Report_Apr-2017.txt: No such file or directory

Advertisement

Answer

Try to double quote the var:

file="Unavailable Voucher's Report_Apr-2017.txt"
scp "$file" user@remoteserver:/path
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement