Bash 5.3.0
Bash 5.3.0
I am a Fedora user so I stay cutting edge, as that is one of the key objectives of the Fedora Project. Though every once in a while, while not opting for going Rawhide (a Fedora Pre-release), I want to check out a new feature in a tool I use a lot. Well, there is probably no tool I use more than my shell
. Bash 5.3.0
Release Candidates (RC) have been available for a while and after reading an article yesterday I just had to check it out. So I went over to GNU and downloaded the latest RC for BASH 5.3.0
. I am checking it out and I like some of the new features. My system default shell is still Bash 5.2.37
. Though my local install allows me to use bash for my personal usage.
This is where how you write a shebang line really comes into play. When using multiple versions of the same shell
on a system. For instance if your shebang line was:
#!/usr/bin/bash
# My really cool script here
# ...
Then the system default would be used. The same would be true for
#!/bin/sh
and #!/bin/bash
as on modern systems they are likely just a symbolic link to /usr/bin/bash
. In fact on Fedora /bin
is a symbolic link to /usr/bin
. To be sure that my scripts use Bash 5.3.0
I use the following shebang:#!/usr/bin/env bash
# My even cooler Bash 5.3.0 script!
# ...
This works because by default,
/usr/local/bin
is before /usr/bin
on the system path. This is by design. So that local installs by your admin (which is probably you) will override system defaults. As /usr/bin/env
uses the system path to find bash
in this later shebang line example it will find my locally installed version of Bash 5.3.0
. This is preferable to hard coding where bash
is on the system. Which could change. I could later decide I wanted to use a custom build of bash
and install it in $HOME/bin
just for my personal use. As $HOME/bin
(by default) precedes both /usr/loca/bin
and /usr/bin
in the system path (this also is by design). My scripts with #!/usr/bin/env bash
will use my custom built bash
as I intended. This type of example is exactly why the POSIX standard recommends this form of shebang line.System scripts will be written with the #!/bin/sh
or #!/usr/bin/bash
form of shebang line so if they have dependencies on that version of the shell I am still safe. I have not broken my system by installing a more recent version of bash
.
note: This is also relevant to MacOS users that install the latest version of bash via homebrew
as homebrew
installs to /usr/local/bin for this reason. To replace software for the user but to leave the system software as is as the system may have dependencies on as specific version of software.
plan-A likes this.
plan-A
in reply to Unus Nemo • — (Proud Eskimo!) •@Unus Nemo
Thanks.
Mine came packed with latest it seem. NOT
not available for me yet..
sudo dnf copr enable c3d/bash
Did you compiled your version of Bash? Is only way with pgp keys ok.
You laid it out, I know