1

So my .profile looks like this:

if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

if [ -f "$HOME/.local/share/profile" ]; then
    . "$HOME/.local/share/profile"
fi


# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
export VISUAL=nano
export EDITOR="$VISUAL"
stty -ixon

function test-func {
        echo test-func
}

alias test-alias='echo test-alias'

When I log into Gnome (on Fedora 35) and open the terminal emulator, I can't execute the function test-func.

$ test-func
bash: test-func: command not found

But when I put the function in my .bashrc file and re-logout and log back in, I am able to execute the test-func function.

Is there a reason why functions added to .profile are not available in the environment?

Edit: So I noticed that when I log in using a non-graphical login (using the Ctrl + Alt + F3 trick), the test-func function is available. Is there a reason why Gnome doesn't make functions in the .profile available to non-login shells?

Edit 2: I also noticed that using a POSIX-compliant syntax for the functions (func-name () { ... } instead of function func-name { ... }) had no effect.

12
  • What login manager are you using? GDM?
    – frabjous
    May 11 at 23:17
  • @frabjous whatever the default one that is included with Fedora 35
    – wheeler
    May 11 at 23:18
  • @thanasisp That answer doesn't explain why functions in .profile aren't loaded in Gnome. I know the .profile is being sourced when I log in, because I can put environment variables in there and they are available in my terminal emulator as well as applications launched directly from Gnome.
    – wheeler
    May 11 at 23:30
  • I believe it is because on Fedora and other modern systemd-logind based login managers, the graphical login is mediated through the systemd --user daemon. It inherits the environment variables of the login shell that launched it, but it directly executes the processes that start your UI. Your gnome-terminal is a child of that process. As far as the shell in your terminal can tell, it has the inherited environment variables but no functions.
    – jsbillings
    May 11 at 23:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.