GNU/Bash 5.1 released with the random ${SRANDOM} number engine

Current GNU/Bash maintainer Chet Ramey announced the latest major release, Bash 5.1, on December 7th, 2020. Bash is the default shell on many Linux distros and popular among developers, especially those working with Linux containers. It is the fifth major release of bash. It came with a new enhanced random number generation and added a new variable called SRANDOM. Let us see how to install and use newly released GNU/BASH 5.1 on Linux.

GNU/Bash 5.1 released

Bash is an acronym for Bourne Again SHell. It is a sh-compatible shell and incorporates KSH and csh. The new release fixes many outstanding bugs in bash-5.0 and introduces several new features. The most significant change is returning to the bash v4.4 behavior of not performing pathname expansion on a word that contains backslashes but does not contain any unquoted globbing special characters.

GNU/Bash 5.1 and the andom ${SRANDOM} number engine

We can create or generate random numbers (sequence of numbers that lack any pattern) under the Bash using the following:

echo "$RANDOM"
printf "%s\n" "$RANDOM"

Here is the bash for loop to test random numbers:

for r in {1..5}
do
  printf "%s\n" "$RANDOM"
done

A new bash variable, SRANDOM added to GNU/Bash-5.1 release, which gets its random data from the system’s entropy engine and is not lined and cannot be reseeded to get an identical random sequence. For instance:

printf "%s\n" "$SRANDOM"
echo "$SRANDOM"
for r in {1..5}; do printf "%s\n" "$SRANDOM"; done


This variable expands to a 32-bit pseudo-random number each time it is referenced. The random number generator is not linear on systems that support /dev/urandom or arc4random, so each returned number has no relationship to the numbers preceding it. The random number generator cannot be seeded, so assignments to this variable have no effect. If SRANDOM is unset, it loses its unique properties, even if it is subsequently reset.

New builtins and other features

  1. There are new loadable builtins mktemp, accept, mkfifo, csv, and cut/lcut.
  2. The shell now expands the history number (e.g., in PS1) even if it is not currently saving commands to the history list.
  3. select builtin now runs traps if its internal call to the read builtin is interrupted by a signal.
  4. Bash now allows SIGINT trap handlers to execute recursively.
  5. Process substitution is now available in posix mode.
  6. ulimit has a -R option to report and set the RLIMIT_RTTIME resource.
  7. Writing history to syslog now handles messages longer than the syslog maxlength by writing multiple messages with a sequence number.

See compete list here online

Installing GNU/Bash 5.1 on Linux and macOS

On Arch Linux all you have to do is type the following pacman command:
# pacman -Syu
macOS users change or install bash using the brew command. Make sure you install Homebrew on macOS and then type the following brew command:
$ brew install bash
Debian bullseye/sid users run the apt command to get the latest release:
$ sudo apt update
$ sudo apt upgrade

A note about source code installation

First install GNU/GCC compiler collectiona as per your OS:

Now grab the tarball using the wget command or download a file with curl:
$ wget https://ftp.gnu.org/gnu/bash/bash-5.1.tar.gz
Untar or extract tar ball, run:
$ tar xvf bash-5.1.tar.gz
The simplest way to compile Bash is to cd into the source code directory using the cd command and then run:
$ cd bash-5.1
$ ./configure

unning ‘configure’ takes some time. While running, it prints messages telling which features it is checking for. Type ‘make’ to compile Bash and build the ‘bashbug’ bug reporting script too:
$ make
Optionally, type ‘make tests’ to run the Bash test suite and then type ‘make install’ to install ‘bash’ and ‘bashbug’. This will also install the manual pages and Info file:
$ sudo make install
Load your new bash and check your bash version:

bash
bash --version
echo "$BASH_VERSION"

Wrapping up

Apart from enhanced random number generation and added a new variable called $SRANDOM in GNU/Bash 5.1, we see many other minor enhancements. Head over to the GNU bash project homepage to grab the latest software.


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz