1

Goal: to run a bash script as the method for builds/runs, by building a runConfiguration that calls the bash script.

I'm using the BashSupport plugin in the latest version of IntelliJ IDEA. I am trying to reference system environment variables from a shell script that is called from a runConfiguration, but I can't pull in system environment variables, unless I manually specify the environment variables in the runConfiguration's XML, which is not an option. I want to be able to pull variables directly from the system. I have tried putting environment variables in /etc/environment and .bashrc and .zshrc.

Any advice would be greatly appreciated!

OS: Ubuntu-based

villasenor
  • 107
  • 3
  • 11
  • 4
    IntelliJ IDEA loads environment variables from the non-interactive (login) shell, see https://youtrack.jetbrains.com/issue/IDEA-146037 and http://bencane.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/. TL;DR: set the environment in `~/.profile`, then logout/login. – CrazyCoder May 06 '17 at 10:25
  • Possible duplicate of [IntelliJ IDEA global environment variable configuration](https://stackoverflow.com/q/45696203/608639) – jww May 31 '19 at 13:04

2 Answers2

2

Thank you @CrazyCoder! That was definitely it. Turns out that after a system restart (not just an IntelliJ restart), IntelliJ was able to pick up the variables I put in /etc/environment. Didn't even need to add them to ~/.profile. Thanks for doing the research!

Josh M.
  • 26,437
  • 24
  • 119
  • 200
villasenor
  • 107
  • 3
  • 11
  • etc/environment is every user. The profile file is just for your current user – OneCricketeer May 07 '17 at 04:53
  • Ah I see. I mean technically I guess that would be fine for a single user machine but I can see how that wouldn't be a best practice. `~/.profile` applies to bash, zsh, and all other shells correct? – villasenor May 07 '17 at 04:56
0

Another solution:

  1. Keep your variables in ~/.bashrc
  2. Create a Run/Debug Configuration using BashSupport plugin
  3. Specify -i in Interpreter options, because if you don't, it will exit ~/.bashrc prematurely

@See .bashrc file

# If not running interactively, don't do anything
case $- in
  *i*) ;;
  *) return;;
esac
#....
Klem231188
  • 106
  • 1
  • 3