Skip to content

Overriden cd fails to switch to paths with spaces #457

Description

@paulourio

When attempting to use the cd command in bash, which runs $HOME/.gvm/scripts/env/cd, to navigate to a directory with spaces in its name, the operation fails with the error message "bash: cd: too many arguments." The expected behavior is a successful navigation to directories with spaces in their names.

How to reproduce:

  1. With initialized GVM, create a directory with spaces in its name:
mkdir -p '~/foo bar'
cd '~/foo bar'
  1. The following error is encountered:
bash: cd: too many arguments

Environment:

  • Operating System: GNU/Linux
  • GVM Version: 1.0.22
  • Bash Version: 5.1.16(1)-release

Activity

  1. haha4github commented on Dec 11, 2023

    @haha4github

    Faced the similar issue

  2. cmodk commented on Dec 26, 2023

    @cmodk

    Have the same issue

  3. albertosouza commented on Jan 22, 2024

    @albertosouza

    After install gvm my cd stopped to work, if run any cd something and nothing happens.
    To solve that for now I deleted $HOME/.gvm/scripts/env/cd script to use the default linux cd.
    That gvm cd script is really need?

  4. M4n5ter commented on Jan 31, 2024

    @M4n5ter

    The same issue

  5. added a commit that references this issue on Feb 6, 2024
  6. added a commit that references this issue on Apr 6, 2024
    14caa88
  7. benyaminl commented on Apr 24, 2024

    @benyaminl

    After install gvm my cd stopped to work, if run any cd something and nothing happens. To solve that for now I deleted $HOME/.gvm/scripts/env/cd script to use the default linux cd. That gvm cd script is really need?

    I tried to delete that but seems it broke the improt of the "cd" in gvm file, could you please also point out where the import of the cd is?

    Thank you

    EDIT: NVM, I delete the row in .gvm/scripts/gvm-default at last row and it solved by itself... (for now for my own bash)

  8. joes commented on May 6, 2024

    @joes

    This was totally unexpected and borks PATH in wsl 2 on windows as well.

    See microsoft/WSL#10399

  9. matthewblott commented on May 29, 2024

    @matthewblott

    I have this issue. I disabled the last command in the scripts/gvm-default file:

    . "$GVM_ROOT/scripts/env/cd" && cd .

    When I inspected the code I noticed there's a cd override function. That seems a bit dangerous to me! I'm on macOS but I'm using bash. I haven't tried with zsh but I suspect it's the same.

  10. jbdemonte commented on Jul 14, 2024

    @jbdemonte

    I have this issue. I disabled the last command in the scripts/gvm-default file:

    . "$GVM_ROOT/scripts/env/cd" && cd .

    When I inspected the code I noticed there's a cd override function. That seems a bit dangerous to me! I'm on macOS but I'm using bash. I haven't tried with zsh but I suspect it's the same.

    I had the cd command no longer working, without any error
    Thanks for your help, I did the same :)

  11. palonsoro commented on Jul 20, 2024

    @palonsoro

    Same for me.

  12. palonsoro commented on Jul 20, 2024

    @palonsoro

    If I manually edit ~/.gvm/scripts/env/cd with the fixes from #482 , the issue no longer happens, so I guess that the issue should be fixed as soon as that PR is merged

  13. yithian commented on Jul 22, 2024

    @yithian

    It looks like this repo hasn't seen any commits in almost a year, so manually applying my fix from #482 may be the only option :(

  14. Abdull commented on Aug 12, 2025

    @Abdull

    To check if you are affected by this issue while using Bash, run the following command: type -a cd (see Bash Builtin Commands: type.

    If type -a cd outputs the following ...

    cd is a function
    # ... contents similar to https://github.com/moovweb/gvm/blob/dd652539fa4b771840846f8319fad303c7d0a8d2/scripts/env/cd
    # ...
    cd is a shell builtin
    

    then execute unset -f cd (see Bourne Shell Builtins: unset in order to "reset" cd back to its original form. Then try cd-ing again and see if the problem is fixed for the moment.

  15. shadowbq commented on Aug 20, 2025

    @shadowbq

    Also for emergency this will work in bash. This will bypass the function and use the builtin.

    builtin cd "A directory with spaces"
  16. leontastic commented on Nov 25, 2025

    @leontastic

    Why does gvm need to override cd?

  17. pieterocp commented on Oct 2, 2026

    @pieterocp

    Removed this and will tell everyone I know to avoid. Why would you do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions