Ubuntu 14.04

Since rc.local is executed as root, does this mean that environment variables of rc.local will be available to all the processes run as root? Why?

Please include references while answering.

closed as unclear what you're asking by Christopher, jimmij, Rui F Ribeiro, X Tian, Archemar Feb 11 at 10:24

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    On what OS? rc.local does very different things on Linux, FreeBSD, and OpenBSD. It probably does very different things on different Linux distributions. – Satō Katsura May 2 '17 at 7:32
  • @SatoKatsura edited – Aquarius_Girl May 2 '17 at 8:27
  • Doesn't Ubuntu 14.04 use systemd? Then rc.local is a systemd-related thing. But even assuming SysV init, environment variables set in a shell script are inherited only by programs that are descendants of said script, and only if they are export-ed. The vast majority of root processes you get to see are descendants of login and / or some X display manager, which have nothing to do with rc.local. – Satō Katsura May 2 '17 at 10:26

No, the scripts in rc.local are run as separate processes, which means they have no way to modify their parent's environment.

If you want to set environment variables system-wide, the place for that is /etc/profile.

The FreeBSD rc.local documentation mentions a convention that /etc/rc.d/ scripts whose name ends with .sh will be sourced rather than executed independently. I don't think this is portable to other platforms, though I could be wrong.

  • please point out the manual where it is mentioned that the scripts in rc.local are run as separate processes. – Aquarius_Girl May 2 '17 at 5:55
  • I don't think it's explicitly mentioned (though "scripts" should suggest this interpretation; if the files were sourced by a shell, surely that would need to be mentioned!), but quick experimentation should easily bear this out. It's also not a heavily standardized mechanism, so the precise documentation depends on your platform. The FreeBSD manual page seems pretty exhaustive: freebsd.org/cgi/man.cgi?query=rc.local&sektion=8 – tripleee May 2 '17 at 5:57

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