Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Jan 2003 13:51:08 -0500
From:      parv <parv_fm@emailgroups.net>
To:        Stijn Hoop <stijn@win.tue.nl>
Cc:        Rob <rob@deathbeforedecaf.net>, "BigBrother (BigB3)" <bigbrother@bonbon.net>, Duncan Anker <d.anker@au.darkbluesea.com>, freebsd-questions@freebsd.org
Subject:   Re: Renaming files with spaces in the name to files without spaces..
Message-ID:  <20030109185108.GA69391@moo.holy.cow>
In-Reply-To: <20030109163044.GG938@pcwin002.win.tue.nl>
References:  <20030108175539.W65616@bigb3server.bbcluster.gr> <200301091519.h09FJIK7000567@goo.0x7e.net> <20030109163044.GG938@pcwin002.win.tue.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
in message <20030109163044.GG938@pcwin002.win.tue.nl>,
wrote Stijn Hoop thusly...
>
> On Fri, Jan 10, 2003 at 01:49:18AM +1030, Rob wrote:
> > > If you want to do it for all files in a directory:
> > >
> > > # for file in *; do mv "$file" `echo $file | sed -e 's/ /_/g'`; done
                                          ^     ^
                                          ^     ^
> > >
> > But if you do this, won't the spaces be mistaken for filename
> > separators?
> 
> No, he has quotes around his $file, and the `` part replaces
> spaces, so this should work.

notice that $file is not enclosed in the sub shell (in between 
``) as an argument to echo.  if the $file happens to have end
blanks, they will be eaten up.  try...

  f=' p q r '; echo $( echo $f | sed 's/ /_/g' )


...output /should/ have been '_p_q_r_', but is 'p_q_r'.


> $ touch "a b" c
> $ for i in *; do echo "arg $i endarg"; done
                        ^             ^
                        ^             ^
> arg a b endarg
> arg c endarg

notice that you have enclosed the string to echo in double quotes,
which preserves the spaces.


  - parv

-- 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030109185108.GA69391>