[tex-k] ls -R

Reinhard Kotucha reinhard.kotucha at web.de
Sun Oct 26 02:14:59 CEST 2003

>>>>> "Olaf" == Olaf Weber <olaf at infovore.xs4all.nl> writes:

    > Assuming we can rely on 'ls' inserting an empty line before each
    > directory (e.g, filenames with newlines in them _will_ break
    > things) and that we can rely on 'sed' not being completely
    > hopeless, the following should fix this.  I would really like to
    > know if for some reason this cannot be used.

Hi Olaf,
it seems to solve the problem.  But my version of sed (GNU sed version
3.02) requires a ';' in front of the '}', otherwise the brace is
interpreted as an option to 's'.

Filenames with newlines are still a problem though it is much less
likely that someone creates such a file accidentally.

BTW, the version of ls I use (GNU fileutils, version 4.0) doesn't
print a newline in this case but replaces it by '\n'.

We could reduce the probability that such a file causes trouble if we
assume that a directory name is prepended by an empty line *and* ends
with a colon.

In this case, the problem will only occur if a filename with a newline
at the end is immediately followed by a filename ending with a colon.

The expression then would be:

    sed '/^$/{n;/:$/s%^\./%%;s%^%./%;};

I don't know how much one can rely on the empty lines in different
versions of ls.  But if you are in doubt, you could run a little test
	mkdir -p ./kpsetest-$$/a/b ; trap ....
	ls -R ./kpsetest-$$ | grep '^$' >/dev/null 
If it fails, the old version should be used.


Reinhard Kotucha			             Phone: +49-511-27060390
Marschnerstr. 25
D-30167 Hannover	                      mailto:reinhard.kotucha at web.de
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.

More information about the tex-k mailing list