I'm trying to export a bash function during Gnome login using one of the login shell start-up scripts. I've tried doing it in ~/.profile and ~/.xprofile but it results in X dying and restarting at the login screen.

I am able to export environment variables from these scripts without problems during Gnome login; only exporting a function (any function, regardless of content) kills X.

I can also source both scripts from a terminal and the function is exported as expected without any problems. The function also gets exported fine if the scripts are invoked by a bash login shell (bash -l) from a terminal.

Why is exporting a function at Gnome login killing X? / Can I do anything to fix it?

(I realise I could export the function from .bashrc, but using a profile is more convenient in my situation and I'd like to understand why this crash is happening.)

  • It would seem useful to provide the function in question. Feb 14, 2011 at 18:10
  • @Ward, it happens with any function. I'll edit the question to clarify that. Feb 14, 2011 at 19:52

2 Answers 2


POSIX sh does not allow functions to be exported, but bash does. ~/.profile is sourced by a POSIX shell, not bash. It's also rather pointless to export functions since only bash can read and use them. Just put the functions in ~/.bashrc, and don't export them.

  • That makes sense. I had been working on CentOS and Darwin for a few days and both seem to run GUI logins through bash shells (allowing function exports from /etc/profile and .bash_profile that become available to all subsequent bash shells). Lesson learnt :) Feb 16, 2011 at 23:02

The accepted answer is incorrect. POSIX-compliant shells do allow functions to be exported.

The problem you had is probably because you were using the function keyword. POSIX syntax does not use function. Remove the function keyword and make sure you have parentheses after the function name and login will work again.

You must log in to answer this question.

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