Skip to main content
edited tags
Link
Braiam
  • 36.9k
  • 29
  • 114
  • 176
Source Link
Aescula
  • 363
  • 3
  • 7

How can a Bash script tell how it was run?

I have a Bash script I was trying to make to help me run a rather complex command with small changes that it would ask me about through echo and read.

I have found solutions to force it to run a terminal to execute the command, but I'm not interested in that. What I would like it to do is, if I space out and just hit Enter on it in Nautilus (making it run with Run Software), it'll just gently pop up a notification saying "Please run this from a terminal."

I can get the popup to happen -- as in I know the command -- but I can't get the Bash script to tell if it's being run inside a terminal or not, it seems to always think so. Is it even possible?