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?

  • In researching this issue I also found autojump. It looks very nice. – MountainX Jul 18 '13 at 22:51

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

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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