Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Use-case: I am working in the terminal in /path/with/a/very/long/name and I want to change to some other directory that is deeply nested. But I don't know the path by memory. So I want to browse via a GUI to enable me to figure out where I need to navigate.

I came up with this script:

echo "change working directory"
MYDIRECTORY=$(kdialog --getexistingdirectory ::label1);
if [ "$?" = 0 ]; then
elif [ "$?" = 1 ]; then
    echo "action canceled";
    echo "ERROR";
exit 0

Unfortunately, it does not work. When the script exits, I remain in the original directory in the terminal. I have learned that this is because my original directory was restored when the subshell that executed the cd command exits.

So how can I accomplish my goal?

share|improve this question
In researching this issue I also found autojump. It looks very nice. – MountainX Jul 18 '13 at 22:51
up vote 3 down vote accepted

Write it as a shell function (e.g. in your .bashrc) rather than a script file.

share|improve this answer
Thanks. I wrote it as a free standing script file and sourced it into my ~/.bashrc – MountainX Jul 18 '13 at 22:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.