Bash 5.0. Main features and where it's included

We’re well into 2019 now, but right at the beginning bash version 5.0 was released. Significant version, since it’s also a major increment, but also with lots of new features and bug fixes included. I’ll write separate posts about some of these features and how we can use them.

My favourite bash 5.0 features

For now, let me tell you which major features included in bash 5.0 I find exciting.

Environment variables

Let’s start with the three new environment variables.

BASH_ARGV0 is a new variable that allows you to set the zeroth argument of a shell script. Of course, this is useful for debugging or beautifying shell scripts – the latter so that it shows a nice name when doing a process listing with ps. Before, you couldn’t have set this zeroth argument, since assigning 0=value would generate an error.

Two time related environment variables are EPOCHSECONDS and EPOCHREALTIME. They contain the number of seconds since epoch, but the latter with a microsecond granularity. This is especially useful in situations when you would normally use printf or date to create time bound file names, with a fair uniqueness certainty – two sequential calls wouldn’t be able to generate the same number in most circumstances.

Builtins and shell options

Three new builtins are also available in bash 5.0: rm, stat, and fdflags.

I’m not sure of how often I remove files, but the new rm builtin ensures that no external execution is performed, so it should be a lot quicker.

I did however use a lot of stat calls in my scripts. Just quickly thinking about it, I think I’ve mostly wanted to check on the size of a file. I do remember having to create a dependency to the stat binary for an RPM package in the past. Now, the stat builtin will again ensure I’m not leaving the bash context to call stat.

The third builtin added was fdflags, which can set the flags on file descriptors or just display the current ones.

Up until now, you had to you the PROMPT_COMMAND variable to be able to send the commands run in interactive shells to the system log (via logger). However, bash 5.0 adds a shell option to enable sending all commands to the system log. It is disabled by default and it’s undocumented. But I’ll find out more and write a special post about it.

And the last feature I’ll be talking about is the localvar_inherit shell option. If set, a local variable will automatically inherit its initial value from the variable in the immediately wider context. This saves some visual space by not having to do local VAR=$VAR, but only local VAR.

There are lots of other features, some of which I’ll explain in some future posts, but these are the ones that I find particularly exciting at this time.

Linux distros that include bash 5.0

However, you might be wondering which version of your favourite Linux distro will include this version of bash. I’m aware that there are other OSes apart from Linux, but I think this one is the major playground for bash.

Most major rolling release distros have picked it up already, including Gentoo, Arch, OpenSUSE Tumbleweed/Factory, Fedora Rawhide, Debian Sid. Good news for Ubuntu 19.04 (Disco), Debian 10 (Buster) and Fedora 30, they’ll have this package upgraded to 5.0 as well.

Not so good news for Redhat/CentOS version 8. Even though it’s in beta, I believe that the package list is well frozen and they won’t update the version of the bash package in the final version. So Redhat/CentOS world will have to wait for another half of decade or so until they’ll get these cool new features. Alpine Linux and Amazon are also lagging in this area at the moment.

Full bash 5.0 features list

The full official list of new features lives in the CHANGES file of the bash 5.0 source tarball. However, Linux Weekly News also provides this full list online, with some very interesting comment threads included.

Now tell me, what bash 5.0 feature excites you the most?

Leave a Reply

Your email address will not be published. Required fields are marked *