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

Simon Scott simon.scott at flexiplan.com
Wed Jul 11 13:54:48 WST 2001



	rm -fR /

	Does the following:

		* You will no longer have any files that begin with a space
		* You will no longer have any files
		* You will find my address and hunt me down like the dog
that I am
		* You will not have to touch a line of PERL :)
		* You will have the chance to reinstall the OS we all love
(windows)
		* You will not make the bonehead mistake of *creating* a
bunch of files with a leading space *ever* again

	Remember, a lesson well learned is worth learning well..... or
something.... :)

	Simon (obviously in a very stupid mood) 	
		


	From:	Leon Brooks <leonb at brooks.fdns.net> on 11/07/2001 01:44 PM
	Please respond to plug at plug.linux.org.au@SMTP at Exchange
	To:	plug at plug.linux.org.au@SMTP at Exchange
	cc:	 

	Subject:	Re: [plug] Remove first sp[ac]e in a filename

	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.





**********************************************************************
This email and any files transmitted with it are confidential and 
intended solely for the use of the individual or entity to whom they   
are addressed. If you have received this email in error please notify 
the system manager.

This footnote also confirms that this email message has been swept by 
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



More information about the plug mailing list