Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

add 'sudo' to 'mv' if file isn't writable by $USER



I'm wondering if someone has already done this.

I have a function which does this:


move () {
	command which -s gmv
	if [ "$?" = "0" ]
	then
		gmv --verbose --backup=numbered $@
	else
		mv -v -i $@
	fi
}

(simply put: use 'gmv' if it exists, otherwise use 'mv')

That works pretty well (although if there are ways to do it better,
please let me know).

HOWEVER, now I want to do

"If $FILE is writable by $USER, do 'move' as above. ELSE use 'sudo'
before the mv or gmv command"

I can probably cobble together a solution, but I thought I'd check
first to see if someone here had already invented this wheel.

TjL



Messages sorted by: Reverse Date, Date, Thread, Author