0

I have just upgraded one of my systems to Precise Pangolin (Ubuntu 12.04). (A long-overdue upgrade from Lucid. Youch!)

When I try to login to X Windows, I get a ~/.xsession-errors file with these contents:

/etc/gdm/Xsession: Beginning session setup...
/etc/gdm/Xsession: 11: /home/username/.profile: function: not found
/etc/gdm/Xsession: 19: /home/username/.profile: RC: not found
Warning: unknown mime-type for "0" -- using "application/octet-stream"
Error: no such file "0"
/etc/gdm/Xsession: 23: /home/username/.profile: Syntax error: "}" unexpected

My normal login shell is ksh, and within .profile I have a function defined - and that function is used within the script a few times. All of the above messages have to do with that function. Definition looks like:

function checkFile {
#<stuff here>
print "${RC}"
}

I cannot seem to find a way around this; don't see a way to make X-windows login recognize an advanced .profile file, and don't see a way to make it ignore .profile nor any lines within it. I've tried creating a .bash_profile and .bash_rc, but still .profile is read when logging in. I also tried wrapping the function (and its callers) around tests for interactive shell.. that just changes the error message to "{ found - expecting fi" or similar.

I don't like being forced into a 1970s box by any software.... what options do I have besides not using these sorts of functions in .profile, and not using X-windows?

Here's a log of what happens when I use a more portable syntax:

username@hpmicro1:/home/username> cat .xsession\-errors
/etc/gdm/Xsession: Beginning session setup...
/etc/gdm/Xsession: 12: /home/username/.profile: Syntax error: "(" unexpected (expecting "fi")

username@hpmicro1:/home/username> more .profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

if [ "${SHELL}" = "/bin/ksh" ]; then
function checkFile() {
2
  • You're using ksh. You got into that box willingly. Commented Mar 16, 2014 at 14:31
  • LOL. Yes, @MichaelHampton, I tend to like advanced technology and superior capabilities. That's why I get disappointed when something tries to pin me into the less capable bash box and its ilk. But this has nothing to do with that religious discussion. bash will also happily process this .profile. So not sure where your comment really comes from, or upon what you have based it.
    – Dennis
    Commented Mar 17, 2014 at 18:40

2 Answers 2

0

You might try a more portable syntax:

checkFile() {
    #<stuff here>
    echo "${RC}"
}
4
  • Actually had already tried that. Tried again in case I'd misstepped. Still no luck.
    – Dennis
    Commented Mar 17, 2014 at 1:23
  • What error messages do you get when using a portable syntax ?
    – jlliagre
    Commented Mar 17, 2014 at 1:33
  • Added in OP. But to summarize: Syntax error: "(" unexpected (expecting "fi")
    – Dennis
    Commented Mar 17, 2014 at 18:32
  • The excerpt you added still has a non portable syntax. There should be no "function" keyword. Testing $SHELL is unreliable.
    – jlliagre
    Commented Mar 17, 2014 at 20:17
0

It sounds like the X server is using a more standard Bourne shell to source your .profile even though your login shell is ksh. Using bash as an example, you can use logic like this before any bash-specific commands in your .profile:

if [ "$BASH" != "" ]; then
  bash stuff
fi

I am sure there would be something in ksh environment that you could use for a similar check.

1
  • No joy. That's what I meant by "I also tried wrapping the function (and its callers) around tests..." The test was: if [ "${SHELL}" = '/bin/ksh' ]; then
    – Dennis
    Commented Mar 16, 2014 at 15:55

You must log in to answer this question.

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