bash script issue
D. Hugh Redelmeier
hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org
Sun Aug 17 22:11:23 UTC 2014
| From: William Muriithi <william.muriithi-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org>
Dealing with filnames with embedded "magic" characters is a hard
problem.
Filesystem:
Underneath it all, NTFS uses UTF16 for its filesystem names.
Who knows for SMB/CIFS (what Samba provides).
As I conceptualize it, UNIX filesystems use a stream of bytes as a
filename. '\0' and '/' are magic, and sometimes '.'. So the shell can
use its own logic.
CD-ROM and relatives have still other rules.
Shell:
BASH and other shells interpret a whole bunch of characters as
special. They lets the user work around this with a variety of kludgy
quoting techniques.
Remember, you are probably affected by the locale!
find(1) and xargs(1) have a way of taking the shell out of the
problem, making it straightforward for some problems
This command, for example, will ls your files no matter how strangely
you named them
find . -name '004*.jpg' -print0 | xargs -0 --no-run-if-empty ls -l --
(I haven't seen -- documented but it seems to work.)
-print0 output doesn't let you do cut(1) etc. straightforwardly.
As has been suggested, if you are willing to forbid '\n' in filenames,
more options open up.
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list