Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

.bashrc – command-based environment variable not being set on new terminal window

In my ~/.bashrc file, I’d like to set an environment variable that itself is the result of running a command:

export PUPPETEER_EXECUTABLE_PATH=`which chromium`

If I open a new terminal window and run env, I do see this environment variable, but it has been set to an empty string:

PUPPETEER_EXECUTABLE_PATH=

If I then run source ~/.bashrc and check env again, I see this value set as I’d expect:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

PUPPETEER_EXECUTABLE_PATH=/opt/homebrew/bin/chromium

Why is it that the results of this command don’t seem to be used to set that environment variable the first time this file is executed when I open a new terminal window? Other non-command-based variables I define in the file are correctly set in new terminals, so I have to assume that it’s something in the way I’ve written the command. Is there a more reliable way to set this so that I don’t have to re-run source ~/.bashrc on every terminal window?

This is on MacOS, Ventura 13.2.1. For reference, here are the contents of ~/.bash_profile and ~/.bashrc, respectively:

[[ -s "$HOME/.bashrc" ]] && source "$HOME/.bashrc"
[[ -s "$HOME/.bash_aliases" ]] && source "$HOME/.bash_aliases"

# Adds brew to PATH
eval "$(/opt/homebrew/bin/brew shellenv)"

# Adds asdf & asdf completions to PATH
. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash

export BASH_SILENCE_DEPRECATION_WARNING=1

# Resolves Puppeteer M1 Mac issue by following the instructions in chetbox's comments at https://github.com/puppeteer/puppeteer/issues/6622
# and making sure to include the --no-quarantine flag when installing Chromium via Homebrew -
# https://github.com/Homebrew/homebrew-cask/issues/112986
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
export PUPPETEER_EXECUTABLE_PATH=`which chromium`

>Solution :

You need to execute the command that updates $PATH before calling which, so it will find the executable.

# Adds brew to PATH
eval "$(/opt/homebrew/bin/brew shellenv)"

[[ -s "$HOME/.bashrc" ]] && source "$HOME/.bashrc"
[[ -s "$HOME/.bash_aliases" ]] && source "$HOME/.bash_aliases"

# Adds asdf & asdf completions to PATH
. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading