From eb4d13126d85665197ed7efc17c1ab442daa70ea Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Mon, 18 Dec 2023 18:39:57 -0800 Subject: 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 --- usr.bin/seq/seq.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/usr.bin/seq/seq.c b/usr.bin/seq/seq.c index 2a35ef51690f..771346df1176 100644 --- a/usr.bin/seq/seq.c +++ b/usr.bin/seq/seq.c @@ -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); } -- cgit v1.2.3