I have a script that I want to have a different behaviour depending on whether it was launched from the terminal or by (double) clicking the icon in the file manager. Can I do this?
Tell me more
×
Super User is a question and answer site for
computer enthusiasts and power users. It's 100% free, no registration required.
|
You can use differences in the return status from
( Or you could use the shell's built-in tests to check whether standard input/output are from/to a terminal:
|
|||
|
|
|
If this is in your in your own computer, with you having make the icon, you could just pass an extra parameter on the command line referred by the icon, such as:
And just test |
|||
|
|
|
Another possible check, see what's in /proc/$PPID/cmdline This is the command line (NUL delimited) of the process that spawned you, |
|||
|
|
envto "scriptenv_$( date +%s )". Start once with each method, and compare the output. – Daniel Beck♦ Nov 21 '11 at 9:44