nitrobass24
nitrobass24

Reputation: 379

Copy File: Name Contains Spaces

I have a large shell script that processes files each of my Solaris systems.

In the beginning the script creates a variable FILENAME Sometimes people create directories/files that contain spaces. e.g.

/users/ldap/Anukriti's System Backup/BACKUP/workspace/BP8/scripts/yui/editor/simpleeditor.js

Later in the script I run

cp $FILENAME $DESTDIR/

As you can imagine this always fails because the following is invalid.

cp /users/ldap/Anukriti's System Backup/BACKUP/workspace/BP8/scripts/yui/editor/simpleeditor.js $DESTDIR

I have tried putting the Variable in Quotes, but this is not working. I have used find with -exec option before, but for this circumstance that is not really an option, especially since Solaris does not support the -wholename or -path options

What can i do here?

Upvotes: 0

Views: 12455

Answers (3)

nitrobass24
nitrobass24

Reputation: 379

Looks like i need to use curly braces for variable expansion and double Quotes

cp "${FILENAME}" $DESTDIR

Upvotes: 2

Jens
Jens

Reputation: 72657

Make sure that

  • $DESTDIR exists
  • is a directory
  • and yes, use double quotes for both variables and get rid of the trailing /.

You might not believe it, but that is your problem. :-)

Upvotes: 0

Gilles Quénot
Gilles Quénot

Reputation: 185219

You just have to protect the variables with quotes :

cp "$FILENAME" "$DESTDIR"

NOTE

Don't use single quotes ', the variables can't be expanded this way.

Upvotes: 9

Related Questions