0

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/).*//'`
MC_PWD_FILE="${TMPDIR-/tmp}/mc-$MC_USER/mc.pwd.$$"
/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)
        fi
        unset MC_PWD
fi

rm -f "$MC_PWD_FILE"
unset 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?

2
  • 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, 2014 at 19:31
  • 1
    @Cyrus Please provide this as an answer, as this solved the same problem for me. Jul 15, 2015 at 0:52

1 Answer 1

2

Using answer above working solution for bash shell is this:

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

OR

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .