2015-05-20 60 views
3

当我用-0运行seq时,为什么它将它视为10? 我已经尝试过两个参数也有三个。这个-0在seq shell命令中意味着什么

[email protected]:~$ seq -0 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 

SEQ(GNU的coreutils)8.21

+1

我的版本'seq(GNU coreutils)8.23)'没有给出任何输出。 –

+0

我的版本('seq(GNU coreutils)8.21')符合这个问题。 –

回答

2

比较coreutils 8.23和8.21源代码。

选项开始-,并具有全数字:

if (argv[optind][0] == '-' 
     && ((optc = argv[optind][1]) == '.' || ISDIGIT (optc))) 
    { 
     /* means negative number */ 
     break; 
    } 

-后,没有考虑到:

if (seq_fast (s1, s2)) 

在8.23,这是固定的:

if (*s1 != '-' && *s2 != '-' && seq_fast (s1, s2)) 

你可以在FTP上获得coreutils源代码:http://ftp.gnu.org/gnu/coreutils/ 文件是src/seq.c

4

看起来你发现了一个bug,http://bugs.gnu.org/17800。这是fixed 2014-06-18

+0

并记住孩子们,始终验证您的输入。有一天,有人给Unicode添加一组新的数字,一段时间后,别人会用它来对付你:-) –

0

那么答案是多在WTF区域buuut让我与该男子页先说明一下:

SEQ(1)用户命令 NAME
序列 - 打印数字

提要

序列
seq [OPTION]... LAST 
    seq [OPTION]... FIRST LAST 
    seq [OPTION]... FIRST INCREMENT LAST 

说明

Print numbers from FIRST to LAST, in steps of INCREMENT. 

    Mandatory arguments to long options are mandatory for short options 
    too. 

    -f, --format=FORMAT 
      use printf style floating-point FORMAT 

    -s, --separator=STRING 
      use STRING to separate numbers (default: \n) 

    -w, --equal-width 
      equalize width by padding with leading zeroes 

    --help display this help and exit 

    --version 
      output version information and exit 

    If FIRST or INCREMENT is omitted, it defaults to 1. That is, an 
    omitted INCREMENT defaults to 1 even when LAST is smaller than FIRST. 
    The sequence of numbers ends when the sum of the current number and 
    INCREMENT would become greater than LAST. FIRST, INCREMENT, and LAST 
    are interpreted as floating point values. INCREMENT is usually 
    positive if FIRST is smaller than LAST, and INCREMENT is usually 
    negative if FIRST is greater than LAST. FORMAT must be suitable for 
    printing one argument of type 'double'; it defaults to %.PRECf if 
    FIRST, INCREMENT, and LAST are all fixed point decimal numbers with 
    maximum precision PREC, and to %g otherwise. 

现在让我们来运行你的命令

Seq -0 

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 

...如果你阅读man page你会看到你不及格的说法也许你所期望的吗?如果你尝试的话,你传递-0作为负0如果你尝试

seg 0 

你不会得到任何东西,因为那么...那就是。现在,如果你想一些有趣的事情型 应打印-0至15

seg -0 15 
-0 
-1 
-2 
-3 
-4 
-5 
-6 
-7 
-8 
-9 
.0 
.1 
.2 
.3 
.4 
.5 
.6 
.7 
.8 
.9 
/0 
/1 
/2 
/3 
/4 
/5 
/6 
/7 
/8 
/9 
00 
01 
02 
03 
04 
05 
06 
07 
08 
09 
10 
11 
12 
13 
14 
15 

因此,要回答你的问题,那么,你给它输入不作指望它,因此它的返回奇怪的结果。你不能拥有-0,所以如果你尝试了-ANY NUMBER,说-3你会看到他们什么都没有返回,所以它可能是一个内置函数返回1-10。

+0

从上面的帖子中也可以看出,它是一个bug;) 看起来你发现了一个bug,http ://bugs.gnu.org/17800。它已于2014-06-18修复。 - 罗伯特卡尔霍恩谢谢!,但我认为我的观点仍然有效,坚持使用它预期使用的方式,你会没事的,有什么用处是-0? –

+0

请忽略手册页中所有不相关的部分。 –

+0

我觉得'seq --help |头-12“就足够了。无需引用整个手册页。 – myaut