开发者

Problem with directory spacing when copying files

开发者 https://www.devze.com 2023-01-08 10:42 出处:网络
I trying to copy a file from a directory to another directory in solaris. DIR1=\"/u01/home files\" DIR2=\"/u01/other files\"

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"
0

精彩评论

暂无评论...
验证码 换一张
取 消