I am trying to write an undefined descriptor in Bash that does the following:
- If there is $ 1 and it is a directory,
cdinto it. - If $ 1 exists inside the user directory
$DEV_DIR, `cd into it. - If the previous conditions do not apply, complete the failure.
I now have something like this:
export DEV_DIR=/Users/federico/programacion/
function command_not_found_handle () {
if [ -d $1 ]; then
cd $1
else
to=$DEV_DIR$1
if [ -d $to ]; then
cd $to
echo `pwd`
else
echo "${1}: command not found"
fi
fi
}
And although it works (the command echo pwdprints the expected directory), the directory in the actual shell does not change.
I got the impression that since this is a function inside mine .bashrc, the shell will not fork, and I could do it cd, but apparently this does not work. Any advice on how to solve this problem would be appreciated.