svn status | grep '\!' | awk '{print $2}' | tee list.$$ | xargs svn revert
xargs svn delete < list.$$
rm list.$$
The tee
command is like a T pipe fitting; one copy of the output goes to each named file and another to standard output. Here, I've named just one file. This forces all the reverts to happen before any of the deletes.The name list.$$
is a simple way of protecting the script from trampling on the files of other processes; there are programs like mktemp
that can be used to create more secure, less predictable names. OTOH, if you aren't running in hostile environments, it is unlikely to matter. If you're being really careful, you'll create a trap
to ensure the file is cleaned up:
tmp=${TMPDIR:-/tmp}/list.$$
trap "rm -f $tmp; exit 1" 0 1 2 3 13 15
svn status | grep '\!' | awk '{print $2}' | tee $tmp | xargs svn revert
xargs svn delete < $tmp
rm $tmp
trap 0
There are other tricks that could be tried, but at least some of them don't guarantee the sequential operation. For example, process substitution in bash
:
svn status | grep '\!' | awk '{print $2}' | tee >(xargs svn revert) | xargs svn delete
Each file will be both reverted and deleted, but the sequencing is not predictable.