Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

#!/bin/sh
echo "change working directory"
MYDIRECTORY=$(kdialog --getexistingdirectory ::label1);
if [ "$?" = 0 ]; then
    cd "$MYDIRECTORY"
elif [ "$?" = 1 ]; then
    echo "action canceled";
else
    echo "ERROR";
fi;
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

1 Answer 1

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

 
discard

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.