So I want to call my .bashrc file for a subprocess in C# to setup some environment variables. I looked at this Set environment variables for a process but is there a simple way to call the .bashrc file for my subprocess without going through and setting all of my environment variables?
1 Answers
The .bashrc
file is meaningless and useless unless the subprocess you are running is, in fact, bash
. However, inasmuch as bash
may indeed be launched if your executable is a shell script, and inasmuch as you can always write a wrapper script around the real intended executable, and inasmuch as you can use bash
's -c
option to run any other command via bash
, putting bash
in the loop isn't a big problem. (That supposes, of course, that you're running on a system that has bash
. I don't necessarily assume that when the host program is in C#.)
Having one way or another gotten bash
into the loop, your options are to read .bashrc
explicitly via the .
or source
command, to pass the -i
option to bash
, or to name .bashrc
via the environment variable BASH_ENV
. Any of these will cause bash
to read commands from your .basrc
, including those setting environment variables.

- 160,171
- 8
- 81
- 157