1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix handling of files without newlines in the head and tail builtins (#365)

The head and tail builtins don't correctly handle files that lack
newlines[*]:
    $ print -n foo > /tmp/bar
    $ /opt/ast/bin/head -1 /tmp/bar  # No output
    $ print -n 'foo\nbar' > /tmp/bar
    $ /opt/ast/bin/tail -1 /tmp/bar
    foo
    bar$
This commit backports the required changes from ksh93v- to handle files
without a newline in the head and tail builtins. (Also note that the
required fix to sfmove was already backported in commit 1bd06207.)

src/lib/libcmd/{head,tail}.c:
- Backport the relevant ksh93v- code for handling files
  without newlines.

src/cmd/ksh93/tests/builtins.sh:
- Add a few regression tests for using 'head -1' and 'tail -1' on a file
  missing and ending newline.

[*]: https://www.illumos.org/issues/4149
This commit is contained in:
Johnothan King 2021-12-07 22:56:52 -08:00 committed by Martijn Dekker
parent beccb93fd4
commit 2b8eaa6609
4 changed files with 52 additions and 12 deletions

3
NEWS
View file

@ -15,6 +15,9 @@ Any uppercase BUG_* names are modernish shell bug IDs.
return value that fits in a signed integer, typically a 32-bit value.
Note that $? is truncated to 8 bits when the current (sub)shell exits.
- The head and tail builtins now correctly handle files that do not have an
ending newline. (Note that the tail builtin is not compiled in by default.)
2021-12-05:
- Fixed an issue on illumos that caused some parameters in the getconf