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 err开发者_JAVA百科or other than renaming the DIR1 not to have spacing?
put quotes around your variables
cp "$DIR1/test.txt" "$DIR2" # or try cp "$DIR1"/test.txt "$DIR2"
(not tested, but you get the idea)
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"
精彩评论