0

I am setting up a Debian 10 with fluxbox window manager. One of the components I need is miniconda, I've installed everything from the initial bash (no desktop) and everything works fine. Miniconda installation alters the /.bashrc file, appending the following lines to its contents:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/opt/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/opt/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

It works fine, the initial (no wm) bash do properly set $PATH, could run conda without problems and echo $PATH would display the included conda installation directory accordingly after a fresh login.

For a terminal created using xterm under Fluxbox, however, I found a behaviour which I would describe as bizarre:

1) Trying to find 'conda' using which gives no answer;

2) echo $PATH does not display the conda installation directory;

3) Yet, conda still works, as I can do conda update conda without problems;

4) After that, the conda installation directory is still not prepended to $PATH and which is still not able to find it;

5) Asking for conda environment activation, e.g. conda activate base works fine, and doing so makes the shell update $PATH properly.

I just want to know why it happens. There is something in this process I could not understand well: How exactly is the way the environment variables are passed to the shell created by xterm in this case? Why is it able to run conda, even though which could not find it in $PATH?

===EDIT=== Including the outputs as required:

root@Zumbi:~# type conda > type_conda_out.txt

conda is a function
conda () 
{ 
    if [ "$#" -lt 1 ]; then
        "$CONDA_EXE" $_CE_M $_CE_CONDA;
    else
        \local cmd="$1";
        shift;
        case "$cmd" in 
            activate | deactivate)
                __conda_activate "$cmd" "$@"
            ;;
            install | update | upgrade | remove | uninstall)
                CONDA_INTERNAL_OLDPATH="${PATH}";
                __add_sys_prefix_to_path;
                "$CONDA_EXE" $_CE_M $_CE_CONDA "$cmd" "$@";
                \local t1=$?;
                PATH="${CONDA_INTERNAL_OLDPATH}";
                if [ $t1 = 0 ]; then
                    __conda_reactivate;
                else
                    return $t1;
                fi
            ;;
            *)
                CONDA_INTERNAL_OLDPATH="${PATH}";
                __add_sys_prefix_to_path;
                "$CONDA_EXE" $_CE_M $_CE_CONDA "$cmd" "$@";
                \local t1=$?;
                PATH="${CONDA_INTERNAL_OLDPATH}";
                return $t1
            ;;
        esac;
    fi
}

root@Zumbi:~# /opt/miniconda3/bin/conda shell.bash hook > hook_out.txt

export CONDA_EXE='/opt/miniconda3/bin/conda'
export _CE_M=''
export _CE_CONDA=''
export CONDA_PYTHON_EXE='/opt/miniconda3/bin/python'

# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause

__add_sys_prefix_to_path() {
    # In dev-mode CONDA_EXE is python.exe and on Windows
    # it is in a different relative location to condabin.
    if [ -n "${_CE_CONDA}" ] && [ -n "${WINDIR+x}" ]; then
        SYSP=$(\dirname "${CONDA_EXE}")
    else
        SYSP=$(\dirname "${CONDA_EXE}")
        SYSP=$(\dirname "${SYSP}")
    fi

    if [ -n "${WINDIR+x}" ]; then
        PATH="${SYSP}/bin:${PATH}"
        PATH="${SYSP}/Scripts:${PATH}"
        PATH="${SYSP}/Library/bin:${PATH}"
        PATH="${SYSP}/Library/usr/bin:${PATH}"
        PATH="${SYSP}/Library/mingw-w64/bin:${PATH}"
        PATH="${SYSP}:${PATH}"
    else
        PATH="${SYSP}/bin:${PATH}"
    fi
    \export PATH
}

__conda_hashr() {
    if [ -n "${ZSH_VERSION:+x}" ]; then
        \rehash
    elif [ -n "${POSH_VERSION:+x}" ]; then
        :  # pass
    else
        \hash -r
    fi
}

__conda_activate() {
    if [ -n "${CONDA_PS1_BACKUP:+x}" ]; then
        # Handle transition from shell activated with conda <= 4.3 to a subsequent activation
        # after conda updated to >= 4.4. See issue #6173.
        PS1="$CONDA_PS1_BACKUP"
        \unset CONDA_PS1_BACKUP
    fi

    \local cmd="$1"
    shift
    \local ask_conda
    CONDA_INTERNAL_OLDPATH="${PATH}"
    __add_sys_prefix_to_path
    ask_conda="$(PS1="$PS1" "$CONDA_EXE" $_CE_M $_CE_CONDA shell.posix "$cmd" "$@")" || \return $?
    rc=$?
    PATH="${CONDA_INTERNAL_OLDPATH}"
    \eval "$ask_conda"
    if [ $rc != 0 ]; then
        \export PATH
    fi
    __conda_hashr
}

__conda_reactivate() {
    \local ask_conda
    CONDA_INTERNAL_OLDPATH="${PATH}"
    __add_sys_prefix_to_path
    ask_conda="$(PS1="$PS1" "$CONDA_EXE" $_CE_M $_CE_CONDA shell.posix reactivate)" || \return $?
    PATH="${CONDA_INTERNAL_OLDPATH}"
    \eval "$ask_conda"
    __conda_hashr
}

conda() {
    if [ "$#" -lt 1 ]; then
        "$CONDA_EXE" $_CE_M $_CE_CONDA
    else
        \local cmd="$1"
        shift
        case "$cmd" in
            activate|deactivate)
                __conda_activate "$cmd" "$@"
                ;;
            install|update|upgrade|remove|uninstall)
                CONDA_INTERNAL_OLDPATH="${PATH}"
                __add_sys_prefix_to_path
                "$CONDA_EXE" $_CE_M $_CE_CONDA "$cmd" "$@"
                \local t1=$?
                PATH="${CONDA_INTERNAL_OLDPATH}"
                if [ $t1 = 0 ]; then
                    __conda_reactivate
                else
                    return $t1
                fi
                ;;
            *)
                CONDA_INTERNAL_OLDPATH="${PATH}"
                __add_sys_prefix_to_path
                "$CONDA_EXE" $_CE_M $_CE_CONDA "$cmd" "$@"
                \local t1=$?
                PATH="${CONDA_INTERNAL_OLDPATH}"
                return $t1
                ;;
        esac
    fi
}

if [ -z "${CONDA_SHLVL+x}" ]; then
    \export CONDA_SHLVL=0
    # In dev-mode CONDA_EXE is python.exe and on Windows
    # it is in a different relative location to condabin.
    if [ -n "${_CE_CONDA+x}" ] && [ -n "${WINDIR+x}" ]; then
        PATH="$(\dirname "$CONDA_EXE")/condabin${PATH:+":${PATH}"}"
    else
        PATH="$(\dirname "$(\dirname "$CONDA_EXE")")/condabin${PATH:+":${PATH}"}"
    fi
    \export PATH

    # We're not allowing PS1 to be unbound. It must at least be set.
    # However, we're not exporting it, which can cause problems when starting a second shell
    # via a first shell (i.e. starting zsh from bash).
    if [ -z "${PS1+x}" ]; then
        PS1=
    fi
fi
root@Zumbi:~# type -f conda
bash: type: conda: not found

===EDIT 2=== Only now, while editing FB's menu, I could see how xterm is called: it is done by a wrapper: x-terminal-emulator -T "Bash" -e /bin/bash --login and the --login option, as explained in bash documentation,

Make bash act as if it had been invoked as a login shell

So it explains why bash was not getting $PATH. Using fbrun xterm results in a bash with the default, initialized system $PATH as expected.

  • It is the same user in both cases? The answer may be in the output of /opt/miniconda3/bin/conda shell.bash hook. Maybe it defines an alias or sets the binary path via hash. What is the output of type conda? – Hauke Laging May 22 at 2:27
  • Same user, root; Sorry, didn't understand quite well which outuput or how to check what you are referering about in /opt/miniconda3/bin/conda shell.bash hook; type conda returns: conda is a function, and includes the code right after. – Mauricio Reis May 22 at 2:44
  • Can you please edit your question and add the output of type -f conda? – Andy Dalton May 22 at 3:43
  • 1
    Phrasing this in terms of "xterm executes" and "terminal executes" is wrong. It is not XTerm that is executing stuff here. A terminal is not a shell. – JdeBP May 22 at 4:47
  • @AndyDalton outuputs included as asked. – Mauricio Reis May 22 at 4:49
2

Running the command conda works because it is defined as a shell function during shell initialization. The function contains the full path of the binary so there is no need for looking it up in $PATH.

which does not show shell functions (by default).

| improve this answer | |

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.