bug-bash
[Top][All Lists]
Advanced

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

Re: Paste with null delimiter


From: Eric Blake
Subject: Re: Paste with null delimiter
Date: Tue, 3 Nov 2015 13:32:47 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 11/03/2015 01:09 PM, Dennis Williamson wrote:
> On Nov 3, 2015 12:47 PM, "Julio C. Neves" <julio.neves@gmail.com> wrote:
>>
>> Thanks Dennis,
>> I know that you are rigth, but "paste -d"" odd even" and "paste -d "" odd
> even" are not the same? The diference is only a space between the option
> and its parameter.

They are indeed not the same.  In long option form, you have:

paste -d "" odd even
 ==
paste --delimiters="" odd even
 ==
paste --delimiters= odd even
 ==
paste --delimiters "" odd even

while:

paste -d"" odd even
 ==
paste -d odd even
 ==
paste --delimiters=odd even
 ==
paste --delimiters odd even

Remember, the shell strips quotes before it hands arguments to paste.
Thus, paste is receiving, as argv, ["paste", "-d", "", "odd", "even"]
for the first group, and ["paste", "-d", "odd", "even"] for the second
group.

There is NO way for any program using getopt() or getopt_long() to know
if the user spelled '-d""' vs. '"-d"' vs. '-d', or any other myriad of
patterns where the quotes are stripped.  The ONLY way to pass an empty
string argument to a short option is to do it as a separate argument,
because the quotes are already stripped by the time argv is formed.
Thus, the space is essential.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]