0

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.

1 Answers1

3

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.

tripleee
  • 7,699