coreutils
[Top][All Lists]
Advanced

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

nl: -d option with a single character


From: KOBAYASHI Takashi
Subject: nl: -d option with a single character
Date: Sun, 13 Dec 2020 15:23:22 -0800

Hello,

I found a bug of -d in nl when a single character is specified. The patches
are also attached. I think there are two ways to fix this.

The current behavior:
$ echo -e 'a\n@:@:\nb\n@@\nc' | nl -d '@'
     1 a
     2 @:@:
     3 b
     4 @@
     5 c

POSIX expectations(Attach: nl-d-posix.patch):
$ echo -e 'a\n@:@:\nb\n@@\nc' | nl -d '@'
     1 a

     1 b
     2 @@
     3 c

POSIX(1003.1-2017)
> -d  delim
> Specify the delimiter characters that indicate the start of a logical
page section. These can be changed from the default characters "\:" to two
user-specified characters. If only one character is entered, the second
character shall remain the default character ':'.

Also, Texinfo is written in the same behavior as POSIX.
> ‘-d CD’
> ‘--section-delimiter=CD’
>     Set the section delimiter characters to CD; default is ‘\:’.  If
>     only C is given, the second remains ‘:’.  (Remember to protect ‘\’
>     or other metacharacters from shell expansion with quotes or extra
>     backslashes.)


I don't like this complex POSIX specification because it doesn't allow us
to specify a single character delimiter.
Does anyone know why POSIX was specified the way it was? I would like to
know the background.
I believe that the section delimiter should be generated from the string
given to the option, regardless of the length of the characters. And by the
string given two characters, it is possible to make the second character
":".

The following is more clear(Attach: nl-d-incompatible.patch):
$ echo -e 'a\n@:@:\nb\n@@\nc' | nl -d '@'
     1 a
     2 @:@:
     3 b

     1 c
$ echo -e 'a\n@:@:\nb\n@@\nc' | nl -d '@:'
     1 a

     1 b
     2 @@
     3 c

Best regards,

KOBAYASHI Takashi

Attachment: nl-d-posix.patch
Description: Text Data

Attachment: nl-d-incompatible.patch
Description: Text Data


reply via email to

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