[openbeos] Re: started from shell or mouseclick ?

  • From: François Revol <revol@xxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Sat, 03 May 2003 15:46:16 +0200 (CEST)

En réponse à Ulrich Scholz <scholly@xxxxxxxxxxxx>:

> moin, moin...
> 
> Is it possible for a program to detect, whether it was started
> from the Terminal or by Icon-Click ?
> 
> It doesn't matter, what Terminal (bash/muterm) or which Tracker.
> 
> In the bash I can use a script:
> 
> ======
> 
> #! /bin/sh
> 
> alert --info $TERM ok
> 
> ======
> 
> It gives my "dumb" when started by doubleclick or "beterm"
> when started from bash.
> 
> Is this "system-variable" $term also readable from an app so
> that the app can decide, whether it was started from terminal
> or tracker ?
> 
> Or is there a better way to get this infornation ?

In bash the best way is:

if tty >/dev/null ; then
# run with a tty attached (from Terminal)
else
# run from Tracker
fi

You can also check for the TTY environment variable
If it's not present (getenv("TTY") returns NULL), then you 
are run from Tracker or at least not from a Terminal.

Also note that Tracker always run programs with the 
current working directory as $HOME
(that's why you see sometimes cd "`dirname "$0"`" in shell
scripts).

François.


Other related posts: