Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.)

share|improve this question
    
It would seem useful to provide the function in question. –  Ward Muylaert Feb 14 '11 at 18:10
    
@Ward, it happens with any function. I'll edit the question to clarify that. –  Ian Mackinnon Feb 14 '11 at 19:52

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
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 :) –  Ian Mackinnon Feb 16 '11 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.