简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM