问题
Currently, working with rhel. Need to create a script that can use a mapping file (source and target need to be dynamic). What file type should be used for the mapping file (.csv, .txt, .json)?
- End directory in a slash e.g.
src/
-r
can be used against a file e.g.cp -r src/file.fil tgt/
- script will be kicked off by the spec file and files will be copied during build
- source and target need to be dynamic
Script example
cp -r src/file.fil tgt/
Mapping file
<src>\t<tgt>\n
e.g. src/file.fil \t tgt/ \n
OR 'src/file.fil'\t'tgt/'\n
回答1:
xargs can be used for that
xargs --arg-file your-file.txt cp
file should contain lines like
file1 tgt/
file2 tgt/
or a for loop reading from a file with just source file names provided that your target is constant
for f in $(cat yourfile.txt); do
cp "$f" tgt/
done
or even
while read src tgt; do
cp "$src" "$tgt"
done < yourfile.txt
来源:https://stackoverflow.com/questions/48286904/rpmbuild-copying-folders-specified-by-a-mapping-file