[Techtalk] detecting whether started at CLI or icon
Kathryn Hogg
kjh at flyballdogs.com
Tue Aug 28 22:17:08 UTC 2012
On 2012-08-28 16:16, Miriam English wrote:
> Hi folks,
>
> I've been fiddling with a shell script that I sometimes start from
> the commandline and sometimes from an icon. It would be nice to have
> some way for it to detect how it started.
>
> Do you know of any inherent difference?
>
> Or do I have to resort to fudging it by doing something like having
> the icon run a different script which then calls the main script
> after
> setting an environment variable or passing a parameter, or something?
For many years, I've done the following in my .profile
tty -s
if [ ! $? ]
then
DT=true
fi
This assumes that when launched from the desktop that its not attached
to a terminal.
Then I use the DT variable to control actions that I want to do when
logged in via a terminal vs logging in on the gui desktop.
Another option you could do is examine the parent process and take
appropriate action.
But what I would probably do is just write a wrapper for your wrapper
and have the icon execute that
#!/bin/sh
# I am cmd-wrapper
exec cmd -gui $*
assuming that cmd is your original script and you add a -gui flag to
indicate that you want the gui features enabled.
--
Kathryn Hogg
http://womensfooty.com
More information about the Techtalk
mailing list