gabelach
gabelach

Reputation: 11

Moving files in different folder changing the names

I am trying to write a script to move some file in a common folder. Basically I have n folders and in each of them there is a file called xmu.dat; I want to copy these files in a different folder changing its names.

This is the code I came up with (I have never written a script before...), but I get some errors:

echo "Folders found:"   
for folder in */
do
   echo "$folder"
   name = ${folder//[\/]/}
   cp ./"$folder"/xmu.dat ./OutputFiles/name
done

Upvotes: 0

Views: 48

Answers (1)

Gustavo Santos
Gustavo Santos

Reputation: 134

As fedorqui said, the issue with your code is the presence of whitespaces around the '='.

If you want to check if a file exists, you can use the '-f' option, as:

if [ -f "$file" ]
then
    echo "$file found."
else
    echo "$file not found."
fi

Upvotes: 2

Related Questions