Bash 5 Features
The newest version of bash, every ones favourite default shell, was recently announced and while reading through the bash 5 release anouncement I noticed a couple of tiny but useful features and an annoyingly described but potentially awesome one.
The tiny but immediately useful additions are a couple of new bash
$EPOCHREALTIME. Rather than scattering
date commands through your scripts you can now use one of these and
save the process execution and command running syntax.
date '+%s' 1548500797 # vs the new, built-in echo $EPOCHSECONDS 1548500798 # and for extra granularity echo $EPOCHREALTIME 1548500799.123456
If you’re writing scripts for wider distribution you probably won’t be able to
rely on the new variables for quite a while but for my personal 10 liners I
can see an immediate code simplification win. Moving on to the potentially impressive feature,
which is described in an awe inspiringly annoying way, we have the potential to
send all history to syslog without adding layers of
PROMPT_COMMANDS and read
only variables. Possibly.
“There is a new (disabled by default, undocumented) shell option to enable and disable sending history to syslog at runtime.”
Disabled by default and undocumented. After a
wget and some
the bash source code I found a basic description:
builtins/shopt.def - syslog_history: a shell option to control whether history is logged to syslog; can be modified at runtime.
None of the modern distros I tried (Fedora rawhide, Ubuntu Disco and the bash 5
container itself) currently have this compiled in so after determining that it’s
not currently available (you can check your own shells with
shopt -p | grep sysl)
I decided to call it a day. I’m not yet willing to invest in a feature none of my
distributions support without maintaining my own complied shell. Still, it’s an
interesting idea and will hopefully be turned on over the next batch of
operating system updates.
If you want to experiment with some of the new bash features, although sadly not the bash syslog logging, you can quickly fire up bash 5 in a docker container:
docker run -ti --rm bash:5.0 bash