cp: missing destination file operand after

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

Im trying to do a full back up and copy over all files from one directory into another directory

    #!/bin/bash       #getting files from this directory     PROJECTDIRECTORY=/../../Project3       #Copied to this directory      FILEBACKUPLOCATION= /../.../FMonday      for FILENAME in $PROJECTDIRECTORY/*     do         cp $FILENAME $FILEBACKUPLOCATION         done   

But I keep getting this error

./fullbackup: line 6: /../../FMonday: Is a directory cp: missing destination file operand after 

回答1:

I think this is what you need is FILEBACKUPLOCATION=/FMonday/



回答2:

Variable assignments in bash scripts require no space between the variable name and value or (unless quoted) within the value. Since a space was present in the line FILEBACKUPLOCATION= /../.../FMonday, it attempted to execute /../.../FMonday as a command (which caused the first error) with FILEBACKUPLOCATION assigned to an empty string. The variable was then not assigned when the other command further down tried to use it (accounting for the second error).



回答3:

In my case, I just used used space and dot operator after the file name. It worked perfectly.

For Example, darthVader is a file name which is inside F drive. So, I used the command "mv /f/darthVader . "



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!