Since ubuntu 17.10, my scripts don't work the same way they used to do:

cd a*

would change directory to the first directory beginning with a. Now, I get this error:

bash: cd: too many arguments

I guess it now detects multiple arguments due to the multiple directories beginning with a and throws an error. How could I change the behavior of cd to the old way?

  • 1
    Interesting. Never new in 16.04 I could type cd D* and it changes to ~/Desktop. Jan 4 '18 at 11:09
  • 1
    It was already reported to the launchpad as bug 1683576: steps to reproduce, expected and actual behavior needed.
    – N0rbert
    Jan 4 '18 at 11:52

This looks like a bug in Bash: per man builtins the old behaviour is the correct one.

   cd [-L|[-P [-e]] [-@]] [dir]
              Change the current directory to dir.  if dir is not supplied,
              the  value  of  the  HOME shell variable is the default.  Any
              additional arguments following dir are ignored.

You can report the bug on the bug-bash mailing list; more details here.

Actually, the bug was reported (long ago). If you want a fixed Bash now, now, now, here's how to do it properly (tested on 17.10, should work on others as well).

First create a directory to work in, for example:

mkdir ~/bash
cd ~/bash

Get the source package and the build dependencies:

apt-get source bash
sudo apt-get build-dep bash
cd bash-4.4

Edit config-top.h to change this (should be line 32)


to this

/* #define CD_COMPLAINS */

Edit debian/changelog and add an entry like this at the top (you can also use the command dch -i):

bash (4.4-5ubuntu1+cd) artful; urgency=medium

  * Fix cd.

 -- Firas Kraiem <firas@fkraiem.org>  Thu, 04 Jan 2018 21:11:22 +0900

The most important points are to append +foo to the current version number (foo can be any string of lowercase letters; and be careful if you use dch -i, it will increment the last number, so you need to revert it to the current one) and to use the correct release name (artful here). Finally, run dpkg-source --commit.

You can then run the debuild command, and if everything goes well (errors about debsign can be ignored) you should have some .debs in the parent directory, which you can install as usual (there is no need to install all of them, just the ones you have now; use dpkg -l | grep bash to find out).

Note that the version number of the new package is set so that you will automatically get any future update to bash; if the update does not fix the problem, you have to repeat the above process.

  • This question has been closed as a duplicate. This answer is useful and does not appear on the duplicate linked question. It may be worth adding this answer to that question, askubuntu.com/questions/905832/…
    – Arronical
    Jan 4 '18 at 12:48
  • @Arronical Will do; it was closed while I was writing.
    – fkraiem
    Jan 4 '18 at 12:50

I found the same question: Ubuntu 17.04 — bash: cd: too many arguments. Apparently it is a bug.

The workaround proposed there is to create a function, based on the builtin cd command that overrides its behaviour:

cd(){ builtin cd "${@:1:1}"; }

Place the above line into the beginning of your script and then use cd a* as in Ubuntu 16.04. Use export -f cd if you want to use it in a sub shell.

You could define and export the function also in your ~/.bashrc file:

cd(){ builtin cd "${@:1:1}"; }
export -f cd
  • Since you already marked the Q as a duplicate, why bother duplicating the accepted answer from the duplicate Q?
    – Xen2050
    Jan 4 '18 at 12:50
  • @Xen2050, it was hard decision :) because sometimes it is easy to find the essential part of the answer under the question that is marked as duplication. Also these export things are not clarified under the original answer.
    – pa4080
    Jan 4 '18 at 12:56
  • I didn't notice the export, but that does help. I'd have thought "for the rep", but either way here's +10
    – Xen2050
    Jan 4 '18 at 13:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.