Re: Whitespace in filenames



On 2006-02-27, soup_or_power@xxxxxxxxx wrote:
I have inherited some code that looks like this:
if [ ! -f $file ]
then
echo "Error Can't clean >$file<. May have spaces in the
name?"
else
mv "$file" DEL.$file
fi

Quote your variables:

if [ -f "$file" ]
then
mv "$file" "DEL.$file"
else
echo "Error: >$file< does not exist"
fi

I have these questions:

a) can it be rewritten as if [ ! -f "$file" ]...
b) change the mv as mv "$file" "DEL.$file"

Exactly.

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
.



Relevant Pages

  • Re: TOT: Spawn of the Devil
    ... If you get curry on the keyboard you clean it up yourself. ... Dave Fawthrop Please quote, ...
    (uk.tech.digital-tv)
  • Re: Error returns not handled correctly by sysfs.c:subsys_attr_store()
    ... # echo a> allow_restart ... to ->store method but this too is the expected behavior. ... can you please build 2.6.24-rc3 from clean source tree ... I tried with clean 2.6.24-rc3 and get the same bad behavior. ...
    (Linux-Kernel)
  • Re: Article/Repost: One Day at a Time
    ... ~Echo wrote: ... ""......Every day the ex-smoker should wake up thinking that he is not going ... For anyone who has quit smoking has broken free from a very ... [end quote] ...
    (alt.support.stop-smoking)
  • Re: Embedding asf file
    ... And thanks for coming clean on what worked. ... Echo ... >> Echo [MS PPT MVP] ... >>>> When you right click the inserted icon, can you drag it around your ...
    (microsoft.public.powerpoint)
  • Re: Mail.app being blocked?
    ... They say I need an invitation. ... OT: Please learn to quote. ... from the practice of many AOL users in the ... Mail: echo 36199371860304980107073482417748002696458P|dc ...
    (comp.sys.mac.apps)