SUMMARY: mv and file names with blank characters

From: Adam Bisbe <bblp_at_bisbe.net>
Date: Tue Mar 05 2002 - 06:55:31 EST
Thank you all, I have no tested everything, but I will.

Ed Rollison said:
Well, at a guess you're doing something like:
for file in `ls`
do
  mv $file /target_directory/$file
done
---------that's what I do!!!

which will throw up on files with whitespace, because put very simply,
'for' uses a space
as it's field delimiter.
the trick is to add
OLDIFS=$IFS
IFS="
"
at the beginning
and
IFS=$OLDIFS
at the end to avoid any possible clashes later in your script.
What this should do is mean you have a delimiter on a carriage return,
rather than a space.
Of course, for this to work with mv you'll also have to put quotes around
the file name.
-------------------------------------------------
Most of you said put quotes around the name.
-------------------------------------------------
Surendar Dinkar and Modrego K. said:

mv "$file" /target_directory/`echo $file|sed -e 's/ //g'`    to move them
without white spaces .
--------------------------------------------------

-----Original question------------------
In a script I need to

mv $file /target_directory/$file

I am having problems with files that have white spaces on their names, how
can I move those files, or maybe better, rename them without white spaces.
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Tue Mar 5 05:56:09 2002

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:42:36 EST