Is it possible that a script knows where it was called?

Asked

Viewed 50 times

1

I have a script.sh and I wonder if there’s any way he could know where he was called.

ex:

comando=$(existe algum comando pra isso?)
variavel=$AlgumaVariavelDeAmbienteTalvez

if [[ $comando == "x" ]]; then
  echo "fui chamado pelo prompt do windows"

elseif [[ $variavel == "y" ]]; then
  echo "fui chamado pelo terminal do git bash"

elseif [[ $variavel == "z" ]]; then
  echo "fui chamado pelo ctrl + r (executar do windows)"

elseif [[ $comando == "teste" ]]; then
  echo "fui clicado!!<---"
fi

As in the example, there is some variable or command that allows me to identify how it was called??

  • 1

    Maybe the most that can be known is if the script was executed in a terminal or not: https://askubuntu.com/q/729904 - But to know if it was via run menu or double-click I think it makes no difference (both fall in the case "no terminal")

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.