26.6 C
Tuesday, October 19, 2021

GNU/Bash 5.1 released with the new random number engine

Must read

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 "%sn" "$RANDOM"

Here is the bash for loop to test random numbers:

for r in {1..5}
  printf "%sn" "$RANDOM"

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 "%sn" "$SRANDOM"
echo "$SRANDOM"
for r in {1..5}; do printf "%sn" "$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:
$ 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 --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.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:

Source link

- Advertisement -

More articles


Please enter your comment!
Please enter your name here

- Advertisement -

Latest article