[20180511]tmux与PATH环境变量.txt
--//今天使用tmux,无意中发现使用tmux的一个问题.
--//首先定义别名显示PATH,这样可以竖着显示,好看一些:
$ alias path='echo $PATH | tr ":" "\n"'
--//没有启动tmux前:
$ path
/u01/app/oracle/product/11.2.0.4/dbhome_1/jdk/bin
/usr/bin
/usr/kerberos/bin
/usr/local/bin
/bin
/usr/bin
/usr/NX/bin
/home/oracle/bin
/u01/app/oracle/product/11.2.0.4/dbhome_1/bin
/home/oracle/anysql
$ path | sort|uniq -c
1 /bin
1 /home/oracle/anysql
1 /home/oracle/bin
1 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin
1 /u01/app/oracle/product/11.2.0.4/dbhome_1/jdk/bin
2 /usr/bin
1 /usr/kerberos/bin
1 /usr/local/bin
1 /usr/NX/bin
--//启动tmux后执行:
$ path | sort|uniq -c
1 /bin
2 /home/oracle/anysql
2 /home/oracle/bin
2 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin
2 /u01/app/oracle/product/11.2.0.4/dbhome_1/jdk/bin
3 /usr/bin
1 /usr/kerberos/bin
1 /usr/local/bin
2 /usr/NX/bin
--//可以发现一些PATH路径被设置2次.问题在于tmux登录时重新执行.bash_profile命令.
$ grep -w PATH .bash_profile
PATH=/usr/bin:$PATH:$HOME/bin
export PATH
export PATH=/u01/app/oracle/product/11.2.0.4/dbhome_1/jdk/bin:${PATH}:$ORACLE_HOME/bin:$HOME/anysql
$ path
/u01/app/oracle/product/11.2.0.4/dbhome_1/jdk/bin
/usr/bin
/u01/app/oracle/product/11.2.0.4/dbhome_1/jdk/bin
/usr/bin
/usr/kerberos/bin
/usr/local/bin
/bin
/usr/bin
/usr/NX/bin
/home/oracle/bin
/u01/app/oracle/product/11.2.0.4/dbhome_1/bin
/home/oracle/anysql
/usr/NX/bin
/home/oracle/bin
/u01/app/oracle/product/11.2.0.4/dbhome_1/bin
/home/oracle/anysql
--//偷懒的解决方法是最后.bash_profile结尾加入如下:
export PATH=/u01/app/oracle/product/11.2.0.4/dbhome_1/jdk/bin:/usr/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/NX/bin:/home/oracle/bin:/u01/app/oracle/produbin:/home/oracle/anysql
--//或者执行如下:
export PATH=$(echo $PATH | tr ":" "\n" | sort| uniq | xargs | tr ' ' ':')
--//当然不理它也没有问题
--//重新登录tmux,这样就不会出现2次的情况.
$ path | sort | uniq -c
1 /bin
1 /home/oracle/anysql
1 /home/oracle/bin
1 /u01/app/oracle/produbin
1 /u01/app/oracle/product/11.2.0.4/dbhome_1/jdk/bin
2 /usr/bin
1 /usr/kerberos/bin
1 /usr/local/bin
1 /usr/NX/bin