path - Interesting issues related to how 'cp --parents' works -


i've written short csh script reads file, contains paths files copied, copies files directory:

1 #!/bin/csh 2 # 3 # script copies source , executable files modified solve issues  4 # brought veracode. 5 # 6  7 set tempdir = '~/updatedfiles2' 8  9 foreach line ( "`cat modifiedfiles`" ) *************here cp line************** 10    `cp -a $line $tempdir` ********************************************** 11 end 

which worked fine. i've since decided want preserve paths these files in form of directory tree under same tempdir directory because colisions occuring when files different paths have same names. (i.e. /vobs/emv/integratedclient/jniwrapper/oemimakefile , /vobs/mv_components/utilities/general/oemimakefile)

so, tried use --parents option, so:

1 #!/bin/csh 2 # 3 # script copies source , executable files modified solve issues  4 # brought veracode. 5 # 6  7 set tempdir = '~/updatedfiles2' 8  9 foreach line ( "`cat modifiedfiles`" ) *************here cp line************** 10    `cp -a --parents $line $tempdir` ********************************************** 11 end 

when test it, starts trying copy entirety of system, starting in root directory, not effect want. i'm trying copy on specific files, maintaining directory structure copied.

i've found explanations of --parents, none describe i'm seeing happening. because i'm using --parents wrong? input file? i'm not sure.

the content of modifiedfiles (which value of tempdir) looks this:

... 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 root directory, may effecting --parents. has heard of unrestricted recursive copying, despite specific file paths , no -r argument? misunderstanding --parents?

wow, feel dumb.

after looking through again , again, i've come find i've done wrong.

the actual command above in csh script. when command enclosed in front ticks (``) in csh script, command executed, , out put of command used shell. therefore doing cp, executing output in shell. i'm not sure why recursively copying upward, removing front ticks fixed everything. there previous error ignored in original "working" script, , when added --parents option, broken script broke more.

moral of story, careful of front ticks!

for interested, before:

... 9 foreach line ( "`cat modifiedfiles`" ) *************here cp line************** 10    `cp -a --parents $line $tempdir` ********************************************** 11 end ... 

and after:

... 9 foreach line ( "`cat modifiedfiles`" ) *************here cp line************** 10    cp -a --parents $line $tempdir ********************************************** 11 end ... 

also, 2 of entries in input file commented out in c style /* comment */ causing recursive copying root directory. haha....eh. stupid me.