All pastes #278811 Raw Edit

Mine

public text v1 · immutable
·published 2006-12-14 12:48 UTC
rendered paste body
My aim:

mv /*/**/word/* ../../..

but if anything exists in ../../..
then try to mv it as filename_2, if error then try filename_3, etc






I've ended with:

#!/bin/bash -x
let i=2
for file in /cygdrive/c/cygwin/1111/*/members/*/*; do
		while [[ -d "${file_$i}/../../.." ]]; do 
		let i++
		done

		mv "$file" "${file}/../../.."
		if [ "$?" = "1" ]; then
		mv "$file" "${file}_$i"
		mv "${file}_$i" "${file}_$i/../../.." 
		fi
		let i=2
done



----------------------------------------------------------------------
----------------------------------------------------------------------



function move() 
{ local i dest; dest="$2"; 
	while [[ -d $dest ]]; do 
		let i++; dest="${2}_$i"; 
	done; 
mv "$1" "$dest";