[plug] Remove first sp[ac]e in a filename

Leon Brooks leonb at brooks.fdns.net
Wed Jul 11 13:46:31 WST 2001


Anthony J. Breeds-Taurima wrote:

> for i in * ; do
> 	h=`echo $i | sed -e s/^ //`
> 	if [ "$i != "$h" ] ; then
> 		echo moving \"$i\" to \"$h\"
> 		#mv $i $h
> 	else
> 		echo skipping $i
> 	fi
> done


for i in \ *; do mv -v "$i" "$(echo $i|sed -e 's/^ //')"; done

Does the following:

   * only treats files with leading spaces
   * doesn't strip embedded spaces
   * works everywhere (else the leading space gets stripped B4 the mv)
                      (and filenames with embedded funnies break also)

  * has no hanging strings (unbalanced quotes)

   * fails if a filename contains a double-quote symbol

Sorry, I've been (full disclosure: am) really busy, and then sick, and 
now both else I would have turned up last night. It sounded interesting.

Cheers.





More information about the plug mailing list