What does -0 mean in shell command?

When I run seq with -0, why is it treating it as 10? I tried this with two arguments and three.

praveen@praveen:~$ seq -0
1
2
3
4
5
6
7
8
9
10

      

seq (GNU coreutils) 8.21

+3


source to share


3 answers


Comparison of source codes for Coreutils 8.23 ​​and 8.21.

Parameters starting with -

and having all digits:

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

      

but after that it -

doesn't count:



if (seq_fast (s1, s2))

      

In 8.23 ​​this is fixed:

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

      

You can get the coreutils sources via FTP: http://ftp.gnu.org/gnu/coreutils/ Filesrc/seq.c

+2


source


It looks like you found a bug, http://bugs.gnu.org/17800 . This was fixed on 2014-06-18 .



+4


source


Well, the answer is more in the WTF buuut area, let me explain the man page first:

SEQ (1) Custom Commands NAME
     seq - print sequence of numbers

SYNTAX

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

      

DESCRIPTION

   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.

      

Now run the command YOUR ...

Seq -0

1
2
3
4
5
6
7
8
9
10

      

... If you read the man page, you will see that you are not missing an argument as you would expect? Omitting it -0 as in negative 0 if you try

seg 0

      

you won't get anything because ok ... that's what. Now if you want something interesting like that should print -0 to 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 

      

So, to answer your question, okay, you are giving it input that you don't expect from it, hence its returning weird results. You can't have -0, so if you try -NAME NUMBER, say -3, you'll see they don't return anything, so its probably a built-in function to return 1-10.

0


source