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?
Determine whether a bash script was launched by icon click or from terminal
bashterminal
Best Answer
You can use differences in the return status from
tty
to help you.(
tty -s
runs thetty
command silently)Exit status:
Or you could use the shell's built-in tests to check whether standard input/output are from/to a terminal: