seq(1): Put separator only between the elements.

- Using non-default ('\n') separator will produce an output with the
  separator at the end of the output, eg.

	% echo "[$(seq -s ' ' 0 2)]"
	[0 1 2 ]

- The output should always be followed by a new line character. Currently:

	% seq -s ' ' 0 2
	0 1 2 %

This change makes seq(1) to behave the same way Linux seq(1):

	% echo "[$(seq -s ' ' 0 2)]"
	[0 1 2]

	% seq -s ' ' 0 2
	0 1 2
	%

Approved by:	oshogbo
Differential Revision:	https://reviews.freebsd.org/D43094
This commit is contained in:
Pawel Jakub Dawidek 2023-12-18 18:39:57 -08:00
parent 8f7ed58a15
commit eb4d13126d

View File

@ -181,8 +181,9 @@ main(int argc, char *argv[])
for (step = 1, cur = first; incr > 0 ? cur <= last : cur >= last;
cur = first + incr * step++) {
if (step > 1)
fputs(sep, stdout);
printf(fmt, cur);
fputs(sep, stdout);
prev = cur;
}
@ -202,15 +203,19 @@ main(int argc, char *argv[])
}
if (strcmp(cur_print, last_print) == 0 &&
strcmp(cur_print, prev_print) != 0) {
fputs(last_print, stdout);
fputs(sep, stdout);
fputs(last_print, stdout);
}
free(cur_print);
free(last_print);
free(prev_print);
if (term != NULL)
if (term != NULL) {
fputs(sep, stdout);
fputs(term, stdout);
}
fputs("\n", stdout);
return (0);
}