Handle ssh X11 forwarding in .bashrc

Sep 27, '05 06:29:00AM

Contributed by: kholburn

I have been trying to get X11 forwarding to pass through a Mac. I have it working on one so I know it can be done. I discovered that if you set the DISPLAY variable with a .bashrc fragment like this...

  if [ `ps -awwwux|grep  X11.app |grep -vc grep` -gt 0 ]; then
    export DISPLAY=":0.0"
  fi
...then X11 forwarding won't work because the .bashrc script overwrites the DISPLAY variable. So I had to add an if statement like this (in my ~/.bashrc):
  if [ -z "$DISPLAY" ]; then
    if [ `ps -awwwux|grep  X11.app |grep -vc grep` -gt 0 ]; then
      export DISPLAY=":0.0"
    fi
  fi
[robg adds: I haven't tested this one.]

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050924195842936