I recently installed openSUSE 13.1 and set up the mc in typical why by aliasing mc with mc-wrapper.sh to have it exit into the last working directory in mc instance. However this does not seem to be working. I tried to debug the mc-wrapper.sh script - the echo commands.

MC_USER=`id | sed 's/[^(]*(//;s/).*//'`
/usr/bin/mc -P "$MC_PWD_FILE" "$@"

if test -r "$MC_PWD_FILE"; then
        MC_PWD="`cat "$MC_PWD_FILE"`"
        if test -n "$MC_PWD" && test -d "$MC_PWD"; then
                echo "will cd in : $MC_PWD"
                cd $MC_PWD
                echo $(pwd)
        unset MC_PWD

rm -f "$MC_PWD_FILE"
echo $(pwd)

To my surprise, mc-wrapper-sh does change the directory and is in the directory before exiting but back in bash prompt the working directory is the one from which the script was invoked.

Can it be that some bash settings is required for this to work?

  • 1
    Your script runs as new process with its own environment and can not change the environment of the calling shell. You can only change working directory of your shell if you source your script: source name_of_your_script. – Cyrus Jul 12 '14 at 19:31
  • 1
    @Cyrus Please provide this as an answer, as this solved the same problem for me. – Marcel Korpel Jul 15 '15 at 0:52

Using answer above working solution for bash shell is this:

alias mc='source /usr/lib/mc/mc-wrapper.sh'


alias mc='. /usr/lib/mc/mc-wrapper.sh'
| improve this answer | |
  • works :-) wonder whether F1 in mc also tells us this? – dotbit Oct 8 '19 at 14:20

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.