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

Re: Bash usage: was implicit linkage



On 10/12/2014 at 01:42 PM, Steve Litt wrote:

> On Sun, 12 Oct 2014 09:33:43 +0100 Martin Read <zen75502@zen.co.uk>
> wrote:
> 
>> On 12/10/14 04:12, Peter Zoeller wrote:
>> 
>>> But the nice thing is shell scripting is simplistic easy to learn
>>> and understand.
>> 
>> I refer the audience to David A. Wheeler's essay[1] on how to
>> handle filenames correctly in shell scripts, and to the bug report
>> that he filed against POSIX.1-2008[2] on the subject. From those, I
>> take away the lesson that no, shell scripting is not simplistic,
>> easy to learn, and easy to understand. It just *looks* simplistic,
>> easy to learn, and easy to understand, in ways that make it a
>> horribly effective footgun.
>> 
>> [1] http://www.dwheeler.com/essays/filenames-in-shell.html
> 
> Martin,
> 
> Thanks so much for the preceding resource. It's worth its weight in
> gold, and I've bookmarked it for quick retrieval.
> 
> This essay practically screams out for somebody to write a C program
> that takes an argument of an arbitrary string, finds all files in a
> directory, and returns a long string with those files separated by
> the arbitrary string.

How would you handle the case where the arbitrary string appears in one
or more of the filenames?

The usual approach is by escaping, which is easy enough with a single
character, but offhand I don't see any potentially robust way to do
escaping of an arbitrary string in such a way that the result would be
necessarily clear to the calling shell script. At the very least you'd
probably need an escape syntax complicated enough to obviate most of the
advantages of not needing to handle filename parsing directly in
shell code...

-- 
   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man.         -- George Bernard Shaw

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: