'Catalina bash shopt direxpand missing

I'm new to macOS coming from Windows and Linux. I want to use bash and found how to upgrade bash on Catalina, version now:

GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0), also installed coreutils.

I'm trying to set direxpand in .bashrc (which works as expected in *nix variants): shopt -s direxpand

But when .bashrc is sourced I get an error:

-bash: shopt: direxpand: invalid shell option name

Spent a couple of hours searching online and can't find an answer, can anyone help?

Update 28/07/20 14:08 GMT

Interesting, following other advice before posting, I installed bash with brew and had to set my shell to /usr/local/bin/bash for the terminal app to use it.

So output from bash --version:

GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0)

But echo $BASH_VERSION gives:

3.2.57(1)-release

So something not right there?

Also, output from running shopt does not show direxpand.

Solved 28/07/20 20:00 GMT

For anyone with a similar problem, here's what I found.

bash installed with Catalina did not include the same shell options I have in linux.

The full solution is to install coreutils and bash with brew: brew install coreutils bash

Then add the new version of bash to shells: sudo vi /etc/shells add /usr/local/bin/bash

Then change your user shell: chsh -s /usr/local/bin/bash

Then in terminal preference > general > shells open with > command (complete path) add the new bash /usr/local/bin/bash

After that shopt -s confirms that direxpand is now an option and my .bashrc works as expected.



Solution 1:[1]

When running shopt without arguments you can see the available shopt options you can set. In your case I expect direxpand it's not there.

The workings of the direxpand shopt option depends on the readline library. If bash is compiled without readline support this option will not be there. I expect that is the case for you.

An option would be to compile bash yourself. The accepted answer of this question will show you how to compile bash yourself. You can add the --enable-readline option in configure to force turn on readline support.

Note: compiling yourself might require you to get the readline library in your OS. I expect bash was compiled without it because it is not easily available, but that is for you to figure out.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Veda