Aparna
Aparna

Reputation: 123

Using a variable to define a path

#!/bin/bash
SOURCE="/C/MSDFFiles/IPFiles/Source"

WORKING="/C/MSDFiles/IPFiles/Working"

rm -rf ./Working/*

cp "$SOURCE/"* "$WORKING/" 2> /dev/null

echo "DONE"

I am trying to copy all the files from source to working but its not working, my out put is done but files are not getting transferred in to working folder

Upvotes: 1

Views: 124

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

Judging from the error message

cp: target `\r' is not a directory

there seems to be a problem with the line breaks in your script (\r is Carriage Return). Did you edit the file on Windows?

You should be able to remove those characters with something like

recode ibmpc..latin1 script.sh

or

mv script.sh script.tmp
cat script.tmp | tr -d '\r' > script.sh
rm script.tmp

or

sed -i "s/\r//g" script.sh

Upvotes: 3

user1019830
user1019830

Reputation:

Your problem is likely the result of your script's line endings being currupted by Windows. Linux line-endings are always \n (one newline) but in Windows they are \r\n (a carriage return followed by a newline).

Here you likely have a carriage return character after the path declarations. Remove the carriage return characters from your script and it should resolve the problem.

If you are using vim you can view all non-printable characters in your file with :set list command.

Upvotes: 3

Related Questions