Modernish is a library for writing robust, portable, readable, and powerful programs for POSIX-based shells and utilities.
ISC License
Bot releases are visible (Hide)
Published by McDutchie over 4 years ago
The installer can now bundle a reduced copy of modernish with your
scripts, so they can run portably with a known version of modernish
without requiring prior installation.
This version should not break existing modernish scripts. The new
features selected for backporting to this release seemed like
necessary improvements because they fix important shortcomings in
modernish. From now on, development of new features happens on the
master branch and 0.16.x only gets bugfixes. I mean it this time :)
This version is tested on AIX (7.1), Cygwin, DragonFlyBSD, FreeBSD,
HP-UX (B.11.11), Illumos (DilOS, OmniOS, OpenIndiana), Interix,
Linux (Debian, Gentoo, NixOS, Slackware, Ubuntu), macOS / Mac OS X,
NetBSD, OpenBSD, QNX (6.5), and Solaris (10.1-11.4). Testing on
other systems is wanted!
Some of the less common UNIX systems' default shells are not
compliant with the latest POSIX spec. If modernish reports fatal
shell bugs, make an alternative shell available in $PATH.
Below is a summary of changes, optimisations and fixes.
See the git log for the complete overview with explanations:
git clone -b 0.16 https://github.com/modernish/modernish
cd modernish
git log -p --reverse v0.16.3..v0.16.5
NEW: install.sh -B: bundle the modernish library with your
scripts.
This version adds a -B (Bundle) option to install.sh which
allows bundling any number of scripts with an reduced copy of
modernish into a separate directory tree (indicated using the -D
option) that is ready to run, archive and distribute. This allows
scripts to run immediately and portably with a known version of
modernish, even on systems that don't have modernish installed.
You can indicate a preferred shell with the -s option or you
can have your script be shell-agnostic. Even if a preferred shell
is indicated, modernish will fall back to other shells if the
preferred one isn't available. It is left to the script to check
for required features (typically with thishellhas
).
Details: README.md, Appendix F
var/loop/find: Enhancements for compatibility and the use of
nonstandard primaries:
use var/loop/find
, afind
utility to use for the find loop. For example:use var/loop/find bsdfind
# prefer utility by this nameuse var/loop/find /opt/local/bin
# look for a utility here firstuse var/loop/find /opt/bin/gfind
# try this one firstfind
use var/loop/find
find
as a last resort; modernish will fall back-exec ... {} \;
.var/local, var/loop/for, var/loop/select, var/loop/find:
New --base option: prefix a string/directory before doing --split
or --glob. This provides a way to have an untrusted prefix part
of a path or string not subject to split or glob while doing
these expansions in safe mode. For example, this is more secure
when expanding wildcards on files within a base directory path
input by the user, or passed from untrusted data.
Rationale: 739c959
The var/mapr module is renamed to sys/cmd/mapr. A compatibility
redirect is left so that use var/mapr
will quietly continue to
work in modernish 0.16.x. After 0.16.x, this will display a
warning; still later, it will be removed.
Rationale: 92fea83
sys/cmd/harden: The harden
function now will not harden read
.
Rationale: 62862b2
thisshellhas
:
thisshellhas --show
is now sorted.Initialisation for non-interactive shells (i.e. scripts):
cd
builtin is notNew shell features detected: PROCREDIR, PROCSUBST, TESTERE
New shell bugs detected: BUG_ALIASCSHD, BUG_ALIASPOSX,
BUG_CDPCANON, BUG_CSUBRMLF, BUG_DEVTTY, BUG_LNNONEG,
BUG_PSUBIFSNW, BUG_PSUBIFSWH, BUG_SHIFTERR0, BUG_ZSHNAMES,
BUG_ZSHNAMES2
var/loop: use PROCSUBST (bash/ksh/zsh process substitution) or
PROCREDIR (yash process redirection) where available. This makes
loop entry faster on shells with one of these features, and more
reliable on buggy kernels with a FIFO-related race condition.
Details: 4279d67
92844ef
var/loop/find: LOOP find
handles loop entry considerably faster
and generates loop iterations more efficiently.
Details: 95417d4
shellquote
:
shellquote -P
.Modernish is now tested on two new systems:
Modernish 0.16.x will now once again initialise on ancient mksh
versions with BUG_NOOCTAL + BUG_CMDSPEXIT (such as mksh R44).
use
: When querying (-q or -e options), use
now doesn`t throw
a fatal error on encountering an invalid module name, but returns
exit status 2 instead.
thisshellhas
:
thisshellhas
falsely detected a builtin command if a readonlythisshellhas
hadshellquote
: Security fix: in "double" quoting, control
characters following a $, `, , or " were not translated to $CC*
expansions, so a quoted string could still span lines.
str ematch
: awk fallback version: add bug-compatibility with
Busybox awk.
Details: d188787
On bash 5.0 and later, modernish now sets the localvar_unset
shopt on initialisation, so the shell no longer has the
treacherous QRK_LOCALUNS2 shell quirk.
Bash on NetBSD crashes when detecting DBLBRACKETERE on NetBSD in
a UTF-8 locale. Fix: make this crash non-fatal for modernish.
Details: 4ff76e8
The PSREPLACE feature is broken on mksh versions <= R51. At least
$CCa (\7) fails to be replaced. Modernish now will not detect
this feature on these mksh versions. Among other things, this
fixes shellquote
on them.
sys/base/readlink:
readlink -m
was canonicalising incorrectly whenreadlink -f/-e/-m
did not resolve symlinks in thefoo
or ./foo
.sys/base/tac:
\
was broken.tac
failed to throw a fatal error if awk failed.sys/base/which: which -a
now avoids duplicate output for
duplicate $PATH entries.
sys/cmd/extern, sys/cmd/harden:
Fixed: Empty $PATH elements were not correctly handled as
equivalent to .
(the present working directory).
sys/cmd/mapr (formerly var/mapr):
Fixed: Severe bug that caused data loss in an input steam > 4 MB.
Details: dae120b
var/loop/find: Fixed use of -ok and -okdir in LOOP find
:
LOOP find
would die with a syntaxLOOP find
now correctly handles the -ok somecommand {} +
find
utilities support.var/loop/find: Init now rejects find
utilities that cannot
correctly handle more than one -exec ... {} +
clause (which
caused multiple -iterate
primaries to malfunction). Utilities
with this bug include the standard find
on HP-UX B.11.11.
var/stack/trap, var/local: Fixes for use on an interactive shell.
Details: a111a3c
Fixes for install.sh:
/
.getconf PATH
.