Linux commands not working after sourcing this file
Closed this issue · 6 comments
When I use the script source-cuda.sh to change the cuda version, the LD_LIBRARY_PATH and other variables are properly set but I am unable to even run nvidia-smi. As a matter of fact, even basic commands are not working. I am wondering what could be the problem. Any help would be appreciated.
Also, will creating a symbolic link to /usr/local/cuda achieve the expected behavior? In my case, I tried creating a symbolic link to cuda 10.0 but nvidia-smi is still showing that the Cuda version is 10.2.
hi @sbaktha! can you provide a few more details:
- which operating system do you use?
- do you use bash or a different shell?
- does
nvidia-smi
work properly before you runsource switch-cuda.sh
? - after you sourced the script, is
nvidia-smi
not found anymore or does it provide an error message?
if your environment variables point to /usr/local/cuda-10.2
(e.g., your PATH
looks like this: ...:/usr/local/cuda-10.2/bin:...
), then creating a symlink does not change anything.
closed due to inactivity
Hi, I figured another way to do this by using aliases to just edit the path variables directly. But I would love your help in figuring this out.
I'm using Ubuntu 18.04
My shell is zsh (oh-my-zsh to manage the configuration)
nvidia-smi works perfectly before sourcing this
I found the source of the error. My path variable is pointing only to the cuda directory and nothing else after sourcing the script. So even the basic shell commands (ls, cd ..) and of course other commands as well are not working.
So I take it that since my shell is ZSH, it is messing up. Any help on how to make this work on zsh would be much appreciated.
You can use emulate sh -c "source switch-cuda.sh"
in zsh
You can use
emulate sh -c "source switch-cuda.sh"
in zsh
What does the command mean? Thank you! @MenxLi
You can use
emulate sh -c "source switch-cuda.sh"
in zshWhat does the command mean? Thank you! @MenxLi
It emulate the behaviour of Bourne shell, below are from ChatGPT :)
This zsh command is using the emulate
built-in command to temporarily change the behavior of the current shell to emulate the behavior of the Bourne shell (sh
). Here's a breakdown of the command:
-
emulate sh
: This part of the command instructs the shell to emulate the behavior of the Bourne shell (sh
). This means that certain features or behaviors specific to zsh will be temporarily disabled or modified to behave more like the Bourne shell. -
-c "source switch-cuda.sh"
: This part of the command specifies a command to be executed in the emulated shell. In this case, it is sourcing (running) a script file namedswitch-cuda.sh
. Thesource
command is used to execute commands from a file within the current shell environment.
So, when this command is run in a zsh shell, it will temporarily switch the behavior of the shell to emulate sh
, and then it will execute the commands from the switch-cuda.sh
script within that emulated shell environment.