ramki_ramakrishnan
ramki_ramakrishnan

Reputation: 199

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

Upvotes: 0

Views: 1594

Answers (1)

Zumo de Vidrio
Zumo de Vidrio

Reputation: 2091

Try to double quote the var:

file="Unavailable Voucher's Report_Apr-2017.txt"
scp "$file" user@remoteserver:/path

Upvotes: 2

Related Questions