Issue
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:
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
Answered By - Barmar Answer Checked By - Gilberto Lyons (WPSolving Admin)