1

In zsh, executing the directory path will cd into it. I want to make bash shell to behave the same. The idea is to check and see if the error is bash: /xyz: Is a directory and cd into '/xyz' and silence the error message. For this to work I need a custom error handler. trap catches signals and the mentioned error does not create a signal (or does it?).

This is not about the bash script, but the actual bash shell one uses every day. Is it possible?

hkoosha
  • 211
  • 1
    Umm, by default, zsh gives that exact same error message. – Kusalananda Aug 09 '18 at 10:50
  • @Kusalananda totally my bad. trap "command" ERR actually works. Must look into the plugin oh-my-zsh has activated for me. – hkoosha Aug 09 '18 at 10:53
  • Related questions are https://unix.stackexchange.com/questions/126719/ and https://unix.stackexchange.com/questions/24378/ , where answer comments (also found at https://unix.stackexchange.com/questions/31161/) have addressed this long since. – JdeBP Aug 09 '18 at 13:33

1 Answers1

1

Totally my bad. trap "errHandler" ERR actually works, a typo kept me looking for solution for two hours. Must look into the plugin oh-my-zsh has activated for me by default, because zsh has no such behavior by default.

And by the way, the easy method is to use autocd added in bash 4.0: https://apple.stackexchange.com/a/55424

hkoosha
  • 211