简体   繁体   中英

bash, can't use xargs replstr after redirect

As part of post-commit hook, I try to copy all the files that changed into a local folder - using this script (attached only the relevant part of the script):

svnlook changed ${REPOS} -r ${REV} | sed "s/^....//" | xargs -I {} svnlook cat ${REPOS} {} -r ${REV} > /tmp/commit2/{}

which won't replace the second {} with the xargs argument but use it as is (creating a file name '{}').

Is it possible to replace the argument after the output redirect?

Thanks, Roi

Not like that, no. The shell does the redirections, not xargs . xargs isn't even "aware" that a redirection is happening.

You could use something like the following:

svnlook changed ${REPOS} -r ${REV} |
  sed "s/^....//" | 
  while read -r line ; do 
    svnlook cat ${REPOS} "$line" -r ${REV} > /tmp/commit2/"$line"
  done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM