Conditionally setting DISPLAY variables in bash

A tiny snippet of useful bash shell code today, to help with setting your DISPLAY variable if integrating Cygwin/X into your Windows environment, add it to a .bashrc for effect.

Launching X apps from the ‘Cygwin Terminal’ is smoothed as a result.

#RT Check for XWin and set DISPLAY if present.

ps -a | grep -v grep | grep /usr/bin/XWin > /dev/null

result=$?

if [ “${result}” -eq “0” ] ; then

 export DISPLAY=localhost:0.0

else

echo “No X.org server running, DISPLAY not set.”

fi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s