Ubuntu 17.04 — bash: cd: too many arguments
I couldn't test this on a real 17.04 system yet (only verified that it works on 16.04), but you should be able to override the cd
Bash built-in command with your own custom function, which discards any additional arguments except the first one:
cd(){ command cd "$1" ; }
Update: As suggested in @muru's comment, this version below might work better and support calling cd
without arguments though:
cd(){ builtin cd "${@:1:1}"; }
After you have entered this line above in your terminal, please verify whether cd
now behaves in the way you want. If this is the case, you can make this function definition persistent by appending that line to the end of your ~/.bashrc
file. Otherwise it will vanish as soon as you end your current shell session.
Note that if for whatever reason you temporarily need to use the real cd
Bash built-in command instead of this custom function, you can simply call it with command cd
instead of plain cd
.
Short answer/Workaround
To answer your question in this exact case, this works
cd album*1
But it is probably not the functionality you really want.
What changed?
It appears that config-top.h
in Bash-4.4 was updated to add the following option
/* Define CD_COMPLAINS if you want the non-standard, but sometimes-desired
error messages about multiple directory arguments to `cd'. */
#define CD_COMPLAINS
And builtins/cd.def
refers to your error here:
#if defined (CD_COMPLAINS)
else if (list->next)
{
builtin_error (_("too many arguments"));
return (EXECUTION_FAILURE);
}
#endif
What can I do long-term?:
You could compile your own bash
without the new CD_COMPLAINS, but that would get tedious. You can redefine the cd
functionality like suggested here or you could alias a function like
cd "$(find $1* | head -1)"
Proving it
Bash 4.4 Beta where it still works
#Pulling and unpacking source
$ wget https://ftp.gnu.org/gnu/bash/bash-4.4-beta.tar.gz
$ tar -xzvf bash-4.4-beta.tar.gz
$ cd bash-4.4-beta
#Building, go grab something to drink. It's gonna be a while.
~/bash-4.4-beta$ ./configure
~/bash-4.4-beta$ make
#Check Version
~/bash-4.4-beta$ ./bash --version
GNU bash, version 4.4.0(1)-beta (x86_64-unknown-linux-gnu)
#Enter a clean interactive prompt
~/bash-4.4-beta$ env -i PATH="$PWD:$PATH" ./bash --noprofile --norc
#Test example
bash-4.4$ mkdir album-0{1..2}
bash-4.4$ cd album* && pwd
/home/gkent/bash-4.4-beta/album0-1
Bash 4.4 Stable Release where it doesn't work
#Pulling and unpacking source
$ wget https://ftp.gnu.org/gnu/bash/bash-4.4.tar.gz
$ tar -zxvf bash-4.4.tar.gz
$ cd bash-4.4/
#Building, go grab something to drink. It's gonna be a while.
~/bash-4.4$ ./configure
~/bash-4.4$ make
#Check Version
~/bash-4.4$ ./bash -version
GNU bash, version 4.4.0(1)-release (x86_64-unknown-linux-gnu)
#Enter a clean interactive prompt
~/bash-4.4$ env -i PATH="$PWD:$PATH" ./bash --noprofile --norc
#Test example
bash-4.4$ mkdir album-0{1..2}
bash-4.4$ cd album*
bash: cd: too many arguments
I've never encountered this issue as I always use Tab Completion.
So in your case, rather than having an imprecise guess as to which directory I want, I would type cd al
Tab which if there's only one match, completes it and if there are 2 or more completes up to where the matching ends and TabTab lists the choices.
Here's an example from my system:
cd Un
Tab
cd Unknown
followed by TabTab produces
Unknown/ Unknown Artist - Unknown Album/