Different behaviour of cd with multiple arguments in bash releases

Posting it here something that is puzzling me; upgrading an application server from Jessie to Stretch broke a bash script.

Upon investigation, we narrowed it to a change of behaviour of the cd command. I am not discussing here if what the script is doing is a good idea, or if it could be improved, I am just focusing in a behaviour change /awareness of changes mindset.


$echo *-*
xxxx-1.0b xxxx-run
$cd *-*

cd works and cds to the first directory ; actually *-run is a symbolic link to the same directory.


$echo *-*
xxxx-1.0b xxxx-run
$cd *-*
bash: cd: too many arguments

bash is 4.3.30(1) in Jessie, and 4.4.12(1) in Stretch.

Why the change in behaviour between Jessie and Stretch?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

See the Relase Notes of bash 4.4, especially

qq. There is a new option settable in config-top.h that makes multiple
directory arguments to cd a fatal error.

BTW, I didn’t know. I just googled for “bash cd number 4.4”.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply