Re: remove double quote character from file names
Date: Thu, 16 Feb 2023 12:58:11 UTC
On Thu, 16 Feb 2023 10:49:27 +0000, Steve O'Hara-Smith wrote: > On Thu, 16 Feb 2023 11:24:31 +0100 > Polytropon <freebsd@edvax.de> wrote: > > > exist in the heap of files to be processed. Selecting a good > > delimiter for input files is hard. Using the "IFS = \n" approach > > works - as long as there are no newlines in filenames (which > > I'm not sure could also be allowed)... ;-) > > Newlines are indeed allowed in filenames viz: > > ✓ steve@steve ~/tmp $ touch 'a > file' > ✓ steve@steve ~/tmp $ echo * > a > file > ✓ steve@steve ~/tmp $ rm 'a > file' > > There are only two byte values not allowed in the 254 bytes of a > filename - NUL and /. AS far as I know, I is "sort of" allowed, because it is subject to interpretation by the filesystem: it indicates a directory entry. NUL is actually part of any filename as its terminator, in terms of common C strings ("blablabla<NUL>"). So in conclusion, not even setting IFS to newline when iterating over input file lists makes the thing 100 % safe... > The ls command suppresses most of the nastier > possibilities and displays a ? these days hence the use of echo above. In > times past I have constructed confusing directories with the aid of CR and > BS and even the occasional BEL. Yes, BEL is great, but so are the new possibilities of UTF-8. Those byte sequences (which the filesystem doesn't care about as long as it's not '/' or NUL), especially the many lookalikes for ';' (greek question mark), ' ' (lots of spaces), or '-' (lots of dashes, too), bear a huge potential for confusion or fun, depending on what side you are on, user or sysadmin. Files like " " (invisible) or "*.txt" are possible, and I assume there is even a symbol that looks like '/', so maybe a file that looks (!) like "not/a/directory.c" could be created. The times when seeing LOGIN.COM;1 or SYS1.PARMLIB(IEASYS00) or BOB::SYSMGR$DKA300:[HOME.BOB.SRC.MEOW]STUPID.TXT;42 on a UNIX filesystem were a bit of a surprise are long gone. Long live invisible files! :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...