Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #11822 > unrolled thread
| Started by | julio.neves@gmail.com |
|---|---|
| First post | 2015-11-03 08:29 -0800 |
| Last post | 2015-11-04 15:44 +0000 |
| Articles | 8 — 4 participants |
Back to article view | Back to gnu.bash.bug
Paste with null delimiter julio.neves@gmail.com - 2015-11-03 08:29 -0800
Re: Paste with null delimiter Eric Blake <eblake@redhat.com> - 2015-11-03 10:41 -0700
Re: Paste with null delimiter Andreas Schwab <schwab@linux-m68k.org> - 2015-11-03 18:47 +0100
Re: Paste with null delimiter Eric Blake <eblake@redhat.com> - 2015-11-03 13:32 -0700
Re: Paste with null delimiter Eric Blake <eblake@redhat.com> - 2015-11-03 13:43 -0700
Re: Paste with null delimiter Eric Blake <eblake@redhat.com> - 2015-11-03 13:52 -0700
Re: Paste with null delimiter Andreas Schwab <schwab@linux-m68k.org> - 2015-11-03 22:57 +0100
Re: Paste with null delimiter Stephane Chazelas <stephane.chazelas@gmail.com> - 2015-11-04 15:44 +0000
| From | julio.neves@gmail.com |
|---|---|
| Date | 2015-11-03 08:29 -0800 |
| Subject | Paste with null delimiter |
| Message-ID | <3a207f09-fc2b-4a2e-a6e5-1d33c7479849@googlegroups.com> |
An example is better than thousand words:
$ seq 1 2 9 > odd
$ seq 2 2 10 > even
$ paste -d "" odd even
12
34
56
78
910
$ paste -d"" odd even
2
4
6
8
10
Like you can see, with no space between the option (-d) and the null parameter (""), we have an unexpected result
[toc] | [next] | [standalone]
| From | Eric Blake <eblake@redhat.com> |
|---|---|
| Date | 2015-11-03 10:41 -0700 |
| Message-ID | <mailman.1591.1446572489.7904.bug-bash@gnu.org> |
| In reply to | #11822 |
[Multipart message — attachments visible in raw view] — view raw
On 11/03/2015 09:29 AM, julio.neves@gmail.com wrote: > An example is better than thousand words: > > $ seq 1 2 9 > odd > $ seq 2 2 10 > even > $ paste -d "" odd even > 12 > 34 > 56 > 78 > 910 > $ paste -d"" odd even This is equivalent to: paste -dodd even which is NOT the same as the NUL delimiter as the argument to -d. There is no way to specify an empty string as the option to a short option, except as a separate parameter. This is not a bug in bash, but in your usage. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
[toc] | [prev] | [next] | [standalone]
| From | Andreas Schwab <schwab@linux-m68k.org> |
|---|---|
| Date | 2015-11-03 18:47 +0100 |
| Message-ID | <mailman.1593.1446572883.7904.bug-bash@gnu.org> |
| In reply to | #11822 |
julio.neves@gmail.com writes: > $ paste -d"" odd even This is the same as `paste -d odd even', so the delimiter list is odd. As there is only one file, this in turn is the same as `paste even'. Ultimately this is the same as `cat even'. Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
[toc] | [prev] | [next] | [standalone]
| From | Eric Blake <eblake@redhat.com> |
|---|---|
| Date | 2015-11-03 13:32 -0700 |
| Message-ID | <mailman.1616.1446582779.7904.bug-bash@gnu.org> |
| In reply to | #11822 |
[Multipart message — attachments visible in raw view] — view raw
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
[toc] | [prev] | [next] | [standalone]
| From | Eric Blake <eblake@redhat.com> |
|---|---|
| Date | 2015-11-03 13:43 -0700 |
| Message-ID | <mailman.1617.1446583430.7904.bug-bash@gnu.org> |
| In reply to | #11822 |
[Multipart message — attachments visible in raw view] — view raw
[adding the list back in with permission; please don't send private mails when the discussion may benefit others] [please don't top-post on technical lists] On 11/03/2015 11:03 AM, Julio C. Neves wrote: > Hi Eric, I wrote NUL because my english is not the best of the world, I > wanna mean "empty" delimiter, I was not trying to use the binary zeroes as > delimiter. > > Using a space between the option and the delimiter it works fine, but if > you take off this space, the first file disapears. > > I can't agree that > > paste -d odd even > > is the same as: > > paste -d odd even > I think you typed that wrong, because what you typed is identical. > In the 1st case we are specifying the delimiters as o, d and d again > > let's use the -s option: > > $ paste -sd odd even # o, d & d are the delimiters > 2o4d6d8o10 > $ paste -sd "" odd even # An empty delimiter > 13579 > 246810 > $ paste -sd"" odd even # The same as the 1st > 2o4d6d8o10 Remember, the shell strips quotes before creating the argv[] handed to the paste process. So 'paste -sd"" odd even' is indeed identical to 'paste -sd odd even' - by the time the quotes are stripped, you are left with the same argv[] contents. The space is absolutely important because it is what creates an argv of ["paste", "-sd", "", "odd", "even"] - once the quotes are stripped, you are still left with an empty argument, but only if those quotes that were trying to delineate an empty string weren't adjacent to anything else. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
[toc] | [prev] | [next] | [standalone]
| From | Eric Blake <eblake@redhat.com> |
|---|---|
| Date | 2015-11-03 13:52 -0700 |
| Message-ID | <mailman.1619.1446583934.7904.bug-bash@gnu.org> |
| In reply to | #11822 |
[Multipart message — attachments visible in raw view] — view raw
[adding the list back in, with permission]
On 11/03/2015 11:43 AM, Julio C. Neves wrote:
> I'm sorry to disturb you.
I have no problem replying to messages, so no need to apologize for
disturbing me. My only problem is when messages are sent to just me
instead of the public list, because then it is a waste of resources.
> There are several responses to my question at the
> bash bug's site, but no one tells why the construction paste -s "" ...
> works, maybe because of my bad English
I don't think your English is the barrier here. Bash quoting rules can
be tricky to learn, especially if you don't know at which point quotes
are stripped from the command line before creating the argv[] seen by
the final process.
It might help if you try this:
$ args() { echo "got $# args:"; for a; do printf '.%s.\n' "$a"; done; }
$ args a""
got 1 args:
.a.
$ args a ""
got 2 args:
.a.
..
$
Once you understand that, you will understand why "" must appear
isolated from any other text for it to produce an empty argument,
whether you are trying to pass an empty string to paste or to any other
application.
>
> I'll give up, but if you want to post this consersation on the list fell
> free to do it.
>
> I would like to thank you very much for your help and your time.
>
We're trying to help. If we haven't answered your question yet, then
feel free to try asking it in a different manner.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[toc] | [prev] | [next] | [standalone]
| From | Andreas Schwab <schwab@linux-m68k.org> |
|---|---|
| Date | 2015-11-03 22:57 +0100 |
| Message-ID | <mailman.1633.1446587886.7904.bug-bash@gnu.org> |
| In reply to | #11822 |
Eric Blake <eblake@redhat.com> writes: > There is NO way for any program using getopt() or getopt_long() to know s/using getopt() or getopt_long()// Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
[toc] | [prev] | [next] | [standalone]
| From | Stephane Chazelas <stephane.chazelas@gmail.com> |
|---|---|
| Date | 2015-11-04 15:44 +0000 |
| Message-ID | <mailman.1689.1446651882.7904.bug-bash@gnu.org> |
| In reply to | #11822 |
2015-11-03 08:29:17 -0800, julio.neves@gmail.com: [...] > $ paste -d "" odd even [...] Note that the portable and standard way to paste with no separator is: paste -d '\0' odd even (no, it doesn't insert NUL characters). not paste -d '' odd even which is not standard and won't work with all paste implementations. With traditional paste implementations: $ paste -d '' a b paste: no delimiters -- Stephane
[toc] | [prev] | [standalone]
Back to top | Article view | gnu.bash.bug
csiph-web