Cibin Joseph
Cibin Joseph

Reputation: 1273

Bash script to set env variables does not work when using source and only works with bash -c

The oneAPI toolkit provided by Intel requires sourcing of a bash script to add several executables/libraries to $PATH and other environment variables. For this, the documentation instructs to run a provided script as

source setvars.sh

However, on a fresh Ubuntu 20.04 system (supported by Intel OneAPI), I get the following error.

$ source setvars.sh
  :: ERROR: No env scripts found: No "env/vars.sh" scripts to process.
This can be caused by a bad or incomplete "--config" file.
Can also be caused by an incomplete or missing oneAPI installation.

After pouring through forums, I came upon a workaround here for zsh-type shells. Following those hints, when I run

bash -c 'source setvars.sh'

There are no errors reported and the script runs perfectly. As expected, the env variables are not available after execution of the bash -c command.

One workaround to this, is to do

bash -c 'source setvars.sh; exec bash'

every time I open a new terminal. This is very annoying.

I would like to source setvars.sh somewhere inside .bashrc or .profile and forget about it.

Why does source setvars.sh not work and bash -c 'source setvars.sh' run without errors here.

Upvotes: 0

Views: 1701

Answers (1)

Cibin Joseph
Cibin Joseph

Reputation: 1273

Answering my own question. This turned out to be an issue with the cd command being aliased to cd "$@" && ls. Sourcing the setvars.sh script before the alias definition solved the issue.

Refer discussion on the Intel Communities forum here.

Upvotes: 0

Related Questions