0

This question already has an answer here:

Considering that environment variables defined in a shell are available to the child processes of the shell.
When we open a terminal, it reads .bashrc and executes its commands. That means the .bashrc is available to all the terminals.


I want to know whether the environment variables of bashrc are available to those scripts which are run periodically at fixed intervals? i.e. We manually do not open a terminal to run these scripts.

What if I start QtCreator by clicking on the desktop icon? Will the environment variables of bashrc be available to this QtCreator process? Why?

If not, then what will be the way to supply environment variables to those scripts which do not physically open a terminal?


Please include references while answering.

marked as duplicate by Gilles, Satō Katsura, Archemar, GAD3R, Rui F Ribeiro Jun 10 '17 at 21:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

There are several poorly standardized components here.

Typically, your desktop environment reads your .profile so that its child processes will inherit any variables defined there.

Typically, your desktop environment doesn't read .bashrc at all (though e.g. macOS runs each new Terminal as a login shell, so if Bash is your login shell, its login files are read at that point).

It's not clear what you mean by "run on a timer". If you run something out of cron or at, it will not read any interactive startup files (though you could do something like bash -i scriptname if you wanted to force it).

As far as Bash and thus .bashrc is concerned, the authoritative reference is the Bash documentation.

The portable place to define system-wide variables is /etc/profile though some platforms also support something like /etc/environment. Similarly, $HOME/.profile is the place to define your personal variables for all shells.

  • It's not clear what you mean by "run on a timer" sorry, I was talking about those scripts which are run periodically. – Aquarius_Girl May 2 '17 at 5:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.