Path 与如何';cp——父母';作品

Path 与如何';cp——父母';作品,path,csh,cp,parents,Path,Csh,Cp,Parents,我编写了一个简短的csh脚本,它读取一个文件,其中包含要复制的文件的路径,然后将这些文件复制到一个目录: 1 #!/bin/csh 2 # 3 # This script copies source and executable files modified to solve issues 4 # brought up by Veracode. 5 # 6 7 set tempdir = '~/updatedfiles2' 8 9 foreach line ( "`cat modified

我编写了一个简短的csh脚本,它读取一个文件,其中包含要复制的文件的路径,然后将这些文件复制到一个目录:

1 #!/bin/csh
2 #
3 # This script copies source and executable files modified to solve issues 
4 # brought up by Veracode.
5 #
6 
7 set tempdir = '~/updatedfiles2'
8 
9 foreach line ( "`cat modifiedFiles`" )
*************here is the cp line**************
10    `cp -a $line $tempdir`
**********************************************
11 end
它以前工作得很好。此后,我决定以目录树的形式将这些文件的路径保存在同一
tempdir
目录下,因为当具有不同路径的文件具有相同名称时,会发生合并。 (即
/vobs/emv/integratedClient/jniWrapper/OEMIMAKEFILE
/vobs/mv_components/utilities/general/OEMIMAKEFILE

因此,我尝试使用
--parents
选项,如下所示:

1 #!/bin/csh
2 #
3 # This script copies source and executable files modified to solve issues 
4 # brought up by Veracode.
5 #
6 
7 set tempdir = '~/updatedfiles2'
8 
9 foreach line ( "`cat modifiedFiles`" )
*************here is the cp line**************
10    `cp -a --parents $line $tempdir`
**********************************************
11 end
当我测试它时,它开始尝试复制整个系统,从根目录开始,这不是我想要的效果。我只是试图复制特定的文件,在复制时保持它们的目录结构

我已经找到了一些关于父母的解释,但没有一个能像我所看到的那样描述。是因为我用了
--父母
错了吗?这是我的输入文件吗?我不确定

modifiedFiles
(它是
tempdir
的值)的内容如下所示:

...
4 /vobs/emv/C_API/APIPrivate.cpp
5 /vobs/mv_components/utilities/class/Array.c
6 /vobs/mv_components/utilities/class/String1.c
7 /vobs/mv_components/export_functions/code/write_nastran_ortho3_none.c
...
/vobs
是一个根目录,因此这可能会对
--父目录
产生影响。有没有人听说过无限制的递归复制,尽管有特定的文件路径和无
-r
参数?我是不是误解了父母?

哇,我觉得自己很笨

经过一次又一次的检查,我终于发现我做错了什么

上面的实际命令是csh脚本。在csh脚本中,当一个命令包含在前面的ticks
(``)
中时,该命令被执行,并且该命令的输出被shell使用。因此,我正在执行
cp
,然后在shell中执行输出。我不知道为什么它会递归地向上复制,但去掉前面的勾号就可以修复一切。我在最初的“工作”脚本中忽略了以前的一个错误,当我添加
--parents
选项时,已经坏掉的脚本坏得更厉害

故事的寓意,当心前面的滴答声

对于任何感兴趣的人,在:

...
9 foreach line ( "`cat modifiedFiles`" )
*************here is the cp line**************
10    `cp -a --parents $line $tempdir`
**********************************************
11 end
...
及之后:

...
9 foreach line ( "`cat modifiedFiles`" )
*************here is the cp line**************
10    cp -a --parents $line $tempdir
**********************************************
11 end
...
此外,输入文件中的两个条目以C风格注释掉
/*注释*/
这导致从根目录进行递归复制。哈哈……嗯。愚蠢的我