Re: : bash script issue

"D. Hugh Redelmeier" <[email protected]> Sun, 17 Aug 2014 18:11:23 -0400 (EDT)
Newsgroups gmane.org.user-groups.linux.tolug
Message-ID <[email protected]>
| From: William Muriithi <[email protected]>

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