위반최소한의 놀라움:
bash-5.0$ (for i in {1..1000010}; do echo $i; done) | nl | tail -24
999987 999987
999988 999988
999989 999989
999990 999990
999991 999991
999992 999992
999993 999993
999994 999994
999995 999995
999996 999996
999997 999997
999998 999998
999999 999999
000000 1000000
000001 1000001
000002 1000002
000003 1000003
000004 1000004
000005 1000005
000006 1000006
000007 1000007
000008 1000008
000009 1000009
000010 1000010
bash-5.0$ uname -a
Darwin llc.local 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 20
20; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64
bash-5.0$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.4
[...]
bash-5.0$ _
기대와 비교:
admin@ip-w-x-y-z:~$ (for i in {1..1000010}; do echo $i; done) | nl | tail -24
999987 999987
999988 999988
999989 999989
999990 999990
999991 999991
999992 999992
999993 999993
999994 999994
999995 999995
999996 999996
999997 999997
999998 999998
999999 999999
1000000 1000000
1000001 1000001
1000002 1000002
1000003 1000003
1000004 1000004
1000005 1000005
1000006 1000006
1000007 1000007
1000008 1000008
1000009 1000009
1000010 1000010
admin@ip-w-x-y-z:~$ uname -a
Linux ip-w-x-y-z 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1+deb9u4 (2019-07-19)
x86_64 GNU/Linux
admin@ip-w-x-y-z:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 9.9 (stretch)
Release: 9.9
Codename: stretch
admin@ip-w-x-y-z:~$ _
이에 대한 귀하의 생각과 극복방안이 궁금합니다. 감사해요.
답변1
기본값너비에 의해 추가된 숫자 nl
는 6입니다. 이는 설명서 nl
와POSIX 표준에 의해 지정됨.
macOS는 nl
숫자가 너비보다 길면 숫자를 자르고(수동 문서에서는 이를 문서화함), GNU는 nl
그렇지 않습니다(그러나 문서화하지는 않습니다). 표준 텍스트에서는 두 동작 모두 허용되지 않는 것 같습니다.
6자리 이상이 필요한 줄에 번호를 매기려면 다음 -w
옵션을 사용하여 더 큰 너비를 지정하십시오 nl
.
$ (for i in {1..1000010}; do echo $i; done) | nl -w 7 | tail -24
999987 999987
999988 999988
999989 999989
999990 999990
999991 999991
999992 999992
999993 999993
999994 999994
999995 999995
999996 999996
999997 999997
999998 999998
999999 999999
1000000 1000000
1000001 1000001
1000002 1000002
1000003 1000003
1000004 1000004
1000005 1000005
1000006 1000006
1000007 1000007
1000008 1000008
1000009 1000009
1000010 1000010