From what I understanding, a daemon is a background process, but daemon requires unique config file to set the environment variable.
E.g. Hadoop daemon require hadoop-env.sh to set environment variable
JAVA_HOME, you can't simply get the variable from
The reason is because of daemon as a background process means it's non-interactive, while ~/.bashrc is means to used only from interactive session, to prevent
alias cp='cp -i' case.
And the latest
~/.bashrc has the safe guard on top of the file do not allow non-interactive caller, i.e. without
-i option will return early:
# ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac
It make me wonder why bashrc don't divide the config files to 3 groups, such as:
~/.bashrc_global #(both interactive and non interactive)
So user can simply set
~/.bashrc_global, and no need to add this environment variable in each daemon file, over and over again.
Is there any reason or restriction of why bashrc not support non-interactive on that way or any other way ? OR am I misunderstanding some concepts ?