in message <[EMAIL PROTECTED]>,
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 [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message

Reply via email to