mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Improve and document fast filescan loops (SHOPT_FILESCAN)
From README: FILESCAN on Experimental option that allows fast reading of files using while < file;do ...; done and allowing fields in each line to be accessed as positional parameters. As SHOPT_FILESCAN has been enabled by default since ksh 93l 2001-06-01, the filescan loop is now documented in the manual page and the compile-time option is no longer considered experimental. We must disable this at runtime if --posix is active because it breaks a portable use case: POSIXly, 'while <file; do stuff; done' repeatedly excutes 'stuff' while 'file' can successfully be opened for reading, without actually reading from 'file'. This also backports a bugfix from the 93v- beta. Reproducer: $ echo 'one two three' >foo $ while <foo; do printf '[%s] ' "$@"; echo; done [one two three] Expected output: [one] [two] [three] The bug is that "$@" acts like "$*", joining all the positional parameters into one word though it should be generating one word for each. src/cmd/ksh93/sh/macro.c: varsub(): - Backport fix for the bug described above. I do not understand the opaque macro.c code well enough yet to usefully describe the fix. src/cmd/ksh93/sh/xec.c: sh_exec(): - Improved sanity check for filescan loop: do not recognise it if the simple command includes variable assignments, more than one redirection, or an output or append redirection. - Disable filescan loops if --posix is active. - Another 93v- fix: handle interrupts (errno==EINTR) when closing the input file.
This commit is contained in:
parent
82ff91e9d9
commit
95d695cb5a
9 changed files with 102 additions and 15 deletions
19
NEWS
19
NEWS
|
@ -3,6 +3,25 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
|
|||
|
||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||
|
||||
2022-02-15:
|
||||
|
||||
- A bug was fixed in fast filescan loops (like 'while <file; do ...; done',
|
||||
enabled by default by the SHOPT_FILESCAN compile-time option) in which
|
||||
"$@" incorrectly acted like "$*" within the do...done block.
|
||||
|
||||
- Improved sanity check for filescan loops: they are now only recognised if
|
||||
'while' is followed by a single input redirection without any command
|
||||
name/arguments or variable assignments.
|
||||
|
||||
- As SHOPT_FILESCAN has been enabled by default since ksh 93l 2001-06-01,
|
||||
the fast filescan loop is now documented in the manual page and the
|
||||
compile-time option is no longer considered experimental.
|
||||
|
||||
- Filescan loops are now disabled at runtime if the --posix option is active
|
||||
as they break a portable use case: POSIXly, 'while <file; do stuff; done'
|
||||
repeatedly excutes 'stuff' while 'file' can successfully be opened for
|
||||
reading, without actually reading from 'file'.
|
||||
|
||||
2022-02-12:
|
||||
|
||||
- In multibyte locales such as UTF-8, shell input is no longer corrupted when
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue