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?