I have been googling and experimenting a bit. Basically I'd like to
change:

  . "$CONFIG_FILE" 2>"$ERR"

to something along these lines:

  . "$CONFIG_FILE" 2> >(tee "$ERR" >&2)

There is just one tiny problem: It's bash syntax and doesn't work in sh.
If I change the shebang line of /usr/sbin/lightdm-session to
"#!/bin/bash" it works like a charm. Actually, it works much better,
since it recursively prevents syntax errors in sourced files from
causing fatal errors. OTOH, I suppose that switching to bash wouldn't be
approved just like that. ;)

I got the tip from the first answer at this page:

http://stackoverflow.com/questions/692000/how-do-i-write-stderr-to-a
-file-while-using-tee-with-a-pipe

The answer also includes the equivalent code for sh. I have successfully
applied that approach in stand-alone test scripts, but when moved to
/usr/sbin/lightdm-session, all my attempts so far have caused buggy
behavior.

You might think that something like this should work:

  . "$CONFIG_FILE" 2>&1 >/dev/null | tee "$ERR" >&2

It doesn't. As soon as you add a pipe like that, setting environment
variables via the sourced files fails.

So I'm stuck. Any help from a shell scripting wizard would be much
appreciated.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/678421

Title:
  Error message for a faulty ~/.profile script

To manage notifications about this bug go to:
https://bugs.launchpad.net/gdm/+bug/678421/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to