[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shell Scripting Question



john wrote:

> Sunny Dubey wrote:
> 
> > Hey,
> >
> > how come the followind doesn't seem to work ...
> >
> > for i in `ls -1 /some/dir` ; do
> >         cat /some/dir/"$i" >> /usr/fruits.txt
> > done
> >
> 
> because $i contains lines like:
>     drw-r--r--    2     sunny    sunny    12345 Oct 23 14:09 hello.c
> which is very unlikely to be a filename.

No, it doesn't. You might want to switch to a display font that
distinguishes between a lowercase L and a number 1. If you have TrueType
support in X, I recommend Microsoft's free "Andale Mono" font for anything
monospaced; it has superb on-screen readability, and you can't mistake a
one for a lowercase L, nor a zero for an uppercase O.

Sunny: You don't need to specify -1 when the output of ls is redirected,
as it is in this case. ls defaults to one entry per line when stdout is
not a tty. Also, someone else pointed out that you can set IFS to not
break arguments on spaces; that should do the trick.

Craig



Reply to: