Originally Posted by
jwbrase
Sometimes what you're supposed to do may depend on where you're run from. For example, you may want to use zenity dialogs as your interface if you're running under X, but fall back to a text interface if not.
@OP:
You can test to see if your program is running under X by testing to see if the "display" environment variable is defined.
Code:
if[ -n $DISPLAY ]
then
#Stuff to do if running under X
else
#stuff to do if not running under X
fi
This won't work if your OS uses something other than X for its GUI, but that's not an issue *yet* on most Unix-like systems (but MacOS/iOS and Android are prominent exceptions, and Wayland may eventually replace X on other Unix-likes).
Then, I'd use the good old `trial and error' method:
Code:
if zenity "$z_options"
then
printf '%s\n' "zenity is it" >&2
elif dialog "$d_options"
then
printf '%s\n' "hurray, we are using dialog" >&2
else
printf '%s\n' "err" >&2
fi
Bookmarks