I try to develop Rust
program using newest CLion
, but find I can only pass arguments through command editor:
-- arg1 arg2 ....
I followed Rust tutorial to install Rust
on my Arch Linux
, and found the Rust
directory is indeed added into ~/.profile
file:
$ cat ~/.profile
export PATH="$HOME/.cargo/bin:$PATH"
But after re-login, I couldn’t see Rust
folder is in $PATH
variable:
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/cuda/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
It didn’t take effect!
After reading Arch Linux Bash document, I noticed the following statement which describes ~/.bash_profile
:
If this file does not exist, ~/.bash_login and ~/.profile are checked in that order.
So this means that if ~/.bash_profile
exists,~/.bash_login
and ~/.profile
won’t be checked, right? Let’s do a check:
(1) Use strace
command to record the files’ names related to current user when logining.
$ strace -o out -e open bash -l
$ grep "/home/xiaonan" out
open("/home/xiaonan/.bash_profile", O_RDONLY) = 3
open("/home/xiaonan/.bashrc", O_RDONLY) = 3
open("/home/xiaonan/.bash_history", O_RDONLY) = 3
open("/home/xiaonan/.bash_history", O_RDONLY) = 3
$ exit
logout
As expected, the ~/.profile
, i.e., /home/xiaonan/.profile
wasn’t opened.
(2) Renamed ~/.bash_profile
to pretend it didn’t exist, checked whether ~/.profile
would be read:
$ mv .bash_profile .bash_profile.bak
$ strace -o out -e open bash -l
$ grep "/home/xiaonan" out
open("/home/xiaonan/.bash_profile", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/xiaonan/.bash_login", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/xiaonan/.profile", O_RDONLY) = 3
open("/home/xiaonan/.bash_history", O_RDONLY) = 3
open("/home/xiaonan/.bash_history", O_RDONLY) = 3
$ echo $PATH
/home/xiaonan/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/cuda/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
$ exit
logout
As things turned out, when the ~/.bash_profile
didn’t exist:
open("/home/xiaonan/.bash_profile", O_RDONLY) = -1 ENOENT (No such file or directory)
The bash
would access ~/.bash_login
and ~/.profile
in sequence, and $HOME/.cargo/bin
was added into $PATH
finally.
The solution of this issue is adding following statement in ~/.bash_profile
:
[[ -f ~/.profile ]] && . ~/.profile
Now it works!