0

I have the following code block in the ~/.bashrc file

function command_not_found_handle {
    for dir in $@; do
        path="${path}${dir}/" 
    done
    if [[ -d ${path} ]]; then
        echo "directory exists and and changing to ${path}"
        cd ${path}
    else
        echo "$@ command not found"
    fi
}

I am attaching the output also Here I am trying to apply cd command for the command which is not exists

out put for the above code block
you can see after trying the unusual command it fired command_not_found_handler as expected but here cd is not worked.
Here mycode git is the command which i have to run.This code checks and make the input to directory path mycode/git and I am trying to pass this to cd but it is not working if it works means the title of the Terminal changes to that directory.
To your clarity I am trying the command manually it changes
Manual Entry of cd
So how can I do that?

Ankanna
  • 131
  • 1
  • 7
  • 2
    Maybe you could use `shopt -s autocd` as explained [here](http://unix.stackexchange.com/a/4270/108618). – Kamil Maciorowski Jul 11 '16 at 06:08
  • 1
    Also: [this](http://stackoverflow.com/q/255414) may be the reason why your `cd` doesn't work. – Kamil Maciorowski Jul 11 '16 at 06:24
  • @KamilMaciorowski you got the nice point ....Thanks for the quick response solved the problem – Ankanna Jul 11 '16 at 06:57
  • Glad to know. I have an impression (which may be wrong) that this question and the [previous one](http://superuser.com/q/1099179/432690) target the same root problem that is now solved by `shopt -s autocd`. If I'm right with this, then you have asked wrong questions in the first place. Read [what the XY problem is](http://meta.stackexchange.com/a/66378). – Kamil Maciorowski Jul 11 '16 at 07:10
  • @KamilMaciorowski the first place is actually i do not know about the `command_not_found_handler` where as this one is about the changing directory ........... Any way thanks for the help – Ankanna Jul 11 '16 at 10:21

0 Answers0