Mailing List Archive


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

Re: [tlug] Adding text to the beginning of a file



Arwyn Hainsworth writes:

 > Note that the for loop will iterate over a list of words delimited by
 > spaces, so if you have spaces in your file names the above won't work.
 > I use an ugly hack to get it to work, but I suspect someone else knows
 > a much more elegant way of doing it, so I'm not going to post the
 > hack.

I don't know any way offhand to get file names with spaces to work
under for.  I tried setting IFS to newline and using `ls` instead of
*, but that seems to confuse bash completely in trying to parse the
for statement.

If you have an explicit list of file names, then just surround the
weird ones with ''.  If you are going to compute the list from a file
listing and execute the command on each in sequence, then find
... -exec is probably the way to go.  If you need to execute on all
the file names in one command, find ... -print0 | xargs -0 ... is
probably the way to go.

Why spaces are permitted in file names I don't know, when to the user
NO-BREAK SPACE is visually identical.  The UI could be exactly the
same.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links