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?

5
  • 2
    Maybe you could use shopt -s autocd as explained here. Jul 11, 2016 at 6:08
  • 1
    Also: this may be the reason why your cd doesn't work. Jul 11, 2016 at 6:24
  • @KamilMaciorowski you got the nice point ....Thanks for the quick response solved the problem
    – Ankanna
    Jul 11, 2016 at 6:57
  • Glad to know. I have an impression (which may be wrong) that this question and the previous one 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. Jul 11, 2016 at 7: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, 2016 at 10:21

0

You must log in to answer this question.

Browse other questions tagged .