Bug 236347

Summary: "seq -f string" repeats strings wrong times
Product: Base System Reporter: y
Component: binAssignee: Conrad Meyer <cem>
Status: Closed FIXED    
Severity: Affects Many People    
Priority: ---    
Version: 12.0-RELEASE   
Hardware: Any   
OS: Any   

Description y 2019-03-07 07:03:42 UTC
% seq -f foo 3
foo
foo
foo
foo

repeated 4 times.

% seq -f foo 0
foo
foo
foo

repeated 3 times.
Comment 1 Conrad Meyer freebsd_committer freebsd_triage 2019-03-07 17:52:26 UTC
Separately, seq 0 is broken — prints 1\n0.  Should be empty.
Comment 2 Conrad Meyer freebsd_committer freebsd_triage 2019-03-07 17:54:42 UTC
(In reply to Conrad Meyer from comment #1)
> Separately, seq 0 is broken — prints 1\n0.  Should be empty.

Well, maybe broken is wrong.  It is inconsistent with GNU seq, due to this documented behavior in seq(1):

> When first is larger than last, the default incr is -1.

In GNU seq, default incr is always 1.
Comment 3 Conrad Meyer freebsd_committer freebsd_triage 2019-03-07 18:03:52 UTC
Ok, this is because the check for a final value past 'end' assumes that the format string will include a representation of the iterated value.  Given '-f foo' does not contain '%g' or anything like that, the check is broken.
Comment 4 Conrad Meyer freebsd_committer freebsd_triage 2019-03-07 18:24:38 UTC
Thanks for the report!
Comment 5 commit-hook freebsd_committer freebsd_triage 2019-03-07 18:24:39 UTC
A commit references this bug:

Author: cem
Date: Thu Mar  7 18:24:17 UTC 2019
New revision: 344891
URL: https://svnweb.freebsd.org/changeset/base/344891

Log:
  seq(1): Require user-provided format strings to contain a conversion

  This matches GNU seq, for example.

  For users that are looking for similar functionality, 'jot -b foo N' will
  print 'foo' N times.  See jot(1).

  PR:		236347
  Reported by:	<y AT maya.st>
  Sponsored by:	Dell EMC Isilon

Changes:
  head/usr.bin/seq/seq.c
  head/usr.bin/seq/tests/seq_test.sh