免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3564 | 回复: 9
打印 上一主题 下一主题

在bash环境中如何使PATH变量自动设置! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-02 10:42 |只看该作者 |倒序浏览
我设置了.profile和.bash_profile文件,如下

bash-3.00# cat .bash_profile
export PATH=/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11/bin:/usr/openwin/bin:/usr/openwin/lib:/usr/ccs/bin:/usr/ucb:/usr/dt/bin:/usr/local/bin:/usr/X11/bin:/usr/openwin/bin:/usr/openwin/lib:/usr/ccs/bin:/usr/ucb:/usr/dt/bin:/opt/sfw/bin

bash-3.00# cat .profile
export PATH=/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11/bin:/usr/openwin/bin:/usr/openwin/lib:/usr/ccs/bin:/usr/ucb:/usr/dt/bin:/usr/local/bin:/usr/X11/bin:/usr/openwin/bin:/usr/openwin/lib:/usr/ccs/bin:/usr/ucb:/usr/dt/bin:/opt/sfw/bin

可是每次telnet后,PATH又变回/usr/sbin:/usr/bin

Last login: Thu Jul  2 10:32:12 2009 from dhcp-shenzhen-c
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
bash-3.00# echo $PATH
/usr/sbin:/usr/bin


我该如何做,各位大侠请赐教!

论坛徽章:
0
2 [报告]
发表于 2009-07-02 10:56 |只看该作者
root在默认的 /etc/default/login里面定义的就是/usr/sbin:/usr/bin
你的.profile是放在root的home目录下么

论坛徽章:
0
3 [报告]
发表于 2009-07-02 11:07 |只看该作者
我有点没看明白,LZ要。。。?

论坛徽章:
0
4 [报告]
发表于 2009-07-02 11:09 |只看该作者
.profile要放到你用户的主目录下才可以的。对了,还要加上可执行权限。

论坛徽章:
0
5 [报告]
发表于 2009-07-02 11:13 |只看该作者
想telnet一登录,我的PATH变量就是以下的值

bash-3.00# echo $PATH
/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11/bin:/usr/openwin/bin:/usr/openwin/lib:/usr/ccs/bin:/usr/ucb:/usr/dt/bin:/usr/local/bin:/usr/X11/bin:/usr/openwin/bin:/usr/openwin/lib:/usr/ccs/bin:/usr/ucb:/usr/dt/bin:/opt/sfw/bin

而不是默认的

bash-3.00# echo $PATH
/usr/sbin:/usr/bin


但是发现修改.profile和.bash_profile没用!

我的文件是在root的home目录下的

bash-3.00# cd

bash-3.00# pwd
/

bash-3.00# cat .profile
export PATH=/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11/bin:/usr/openwin/bin:/usr/openwin/lib:/usr/ccs/bin:/usr/ucb:/usr/dt/bin:/usr/local/bin:/usr/X11/bin:/usr/openwin/bin:/usr/openwin/lib:/usr/ccs/bin:/usr/ucb:/usr/dt/bin:/opt/sfw/bin

bash-3.00# cat .bash_profile
export PATH=/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11/bin:/usr/openwin/bin:/usr/openwin/lib:/usr/ccs/bin:/usr/ucb:/usr/dt/bin:/usr/local/bin:/usr/X11/bin:/usr/openwin/bin:/usr/openwin/lib:/usr/ccs/bin:/usr/ucb:/usr/dt/bin:/opt/sfw/bin
bash-3.00#

论坛徽章:
0
6 [报告]
发表于 2009-07-02 11:16 |只看该作者
已经加了执行权限,还是不行

bash-3.00# ls -la .profile
-rwxr--r--   1 root     root         236 Jul  1 10:38 .profile
bash-3.00# ls -la .bash_profile
-rwxr--r--   1 root     root         236 Jul  2 10:39 .bash_profile
bash-3.00# pwd
/
bash-3.00#

在登陆后:
Last login: Thu Jul  2 11:16:16 2009 from dhcp-shenzhen-c
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
bash-3.00# echo $PATH
/usr/sbin:/usr/bin
bash-3.00#

论坛徽章:
0
7 [报告]
发表于 2009-07-02 11:18 |只看该作者
在你的PATH的最后面加上个:. 看看。

论坛徽章:
0
8 [报告]
发表于 2009-07-02 11:34 |只看该作者
楼主的方法还是不行

PS:我修改了/etc/default/login的PATH和SUPATH.现在PATH可以记住配置了.难道只有这种非常规的方法???

论坛徽章:
0
9 [报告]
发表于 2009-07-02 11:47 |只看该作者
你应该用以下格式:
PATH=XXXX
export  PATH


而且,最好确定你的root用sh还是bash登录的,一个一个检查。

[ 本帖最后由 easybegin 于 2009-7-2 11:49 编辑 ]

论坛徽章:
2
丑牛
日期:2014-06-11 13:55:04ChinaUnix元老
日期:2015-02-06 15:16:14
10 [报告]
发表于 2009-07-02 12:08 |只看该作者

回复 #1 zg2000 的帖子

建议这样写:

PATH=$PATHxxxx:.:
export PATH
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP