tags:

views:

18

answers:

2

I trying to copy a file from a directory to another directory in solaris.

DIR1="/u01/home files" DIR2="/u01/other files"

cp $DIR1/test.txt $DIR2

cp: cannot access /u01/home cp: cannot access files.

How do i resolves this error other than renaming the DIR1 not to have spacing?

+1  A: 

put quotes around your variables

cp "$DIR1/test.txt" "$DIR2"  # or try cp "$DIR1"/test.txt "$DIR2"

(not tested, but you get the idea)

ghostdog74
+1  A: 

When you assign a value to a variable in the shell, as in DIR1="/u01/home files", the quotes have special meaning, and are not actually assigned to the variable. So when you reference the variable with $DIR1, there are no spaces.

Try this instead:

cp "$DIR1/test.txt" "$DIR2"
Jason Day