For Loops and Space in Names

Cameron Simpson cs at zip.com.au
Wed Dec 10 00:17:05 UTC 2008


On 09Dec2008 18:24, RGH <rgheck at comcast.net> wrote:
> Since we were talking here about this last week, I thought I'd mention this:
>     
> http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
> Most of the ideas there are ones that got mentioned here, but there is a  
> new one.

If you mean this:

  # a backspace/newline pair without resorting to cumbersome echo
  IFS='^H
  '
  FILES=foo/*
  for f in $FILES
  do

That's awful!

This:

  for f in foo/*
  do

is totally reliable and does not need $IFS hacking (which amounts to
"guess a char I might not see in a filename).

And don't get me started on the evils of using $UPPER_CASE variable names
for script local variables. The $UPPER_CASE names ae routines exported
($PATH, $PS1, $MANPATH, etc etc); lower case is where your locals should
go. (Remember, you will never know the full list of exported variables,
and if you reuse one that is already in the environment then you've just
broken it for every subprogram you call.)

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Network Planning Constraint Of The Month:
        You can't send bits over a non-existant link.
                - Valdis Kletnieks <valdis at vtvm1.cc.vt.edu>




More information about the fedora-list mailing list