aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/seq
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2023-12-19 02:39:57 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2023-12-22 05:54:05 +0000
commiteb4d13126d85665197ed7efc17c1ab442daa70ea (patch)
treefd87dcda6cccb13a8cefab04822ccc5a59d55d0a /usr.bin/seq
parent8f7ed58a15556bf567ff876e1999e4fe4d684e1d (diff)
downloadsrc-eb4d13126d85665197ed7efc17c1ab442daa70ea.tar.gz
src-eb4d13126d85665197ed7efc17c1ab442daa70ea.zip
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
Diffstat (limited to 'usr.bin/seq')
-rw-r--r--usr.bin/seq/seq.c11
1 files 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);
}