linux - 重新启动后echo $SMARTY_DIR 没有结果
高洛峰
高洛峰 2017-04-17 16:09:16
[Linux讨论组]

debian8 是一个普通账户.

debian8@hwy:~$ uname -a
Linux hwy 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u1 (2016-09-03) x86_64 GNU/Linux
debian8@hwy:~$ bash --version
GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

我安装了Smarty到/usr/local/lib/Smarty/,于是写环境变量。

 vim /etc/profile
 export SMARTY_DIR=/usr/local/lib/Smarty/
 source /etc/profile

然后测试:

debian8@hwy:~$ echo $SMARTY_DIR
/usr/local/lib/Smarty/

现在关闭电脑,重新启动,进入普通账户debian8,再次输入

debian8@hwy:~$ echo $SMARTY_DIR 

没有任何输出?请问,如何解决这个问题,出现故障的原因在哪里?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(2)
PHP中文网

建议把

export SMARTY_DIR=/usr/local/lib/Smarty/

写进 ~/.bashrc

/etc/profile这个文件应该只影响sh,对bash的修改来自于/etc/bash.bashrc。你可以尝试一下修改/etc/bash.bashrc。不过修改~/.bashrc是更好的选择。

PHP中文网

这个问题和login shell non-login shell有关,查看了英文资料。

http://unix.stackexchange.com...

prompt> echo $0
-bash # "-" is the first character. Therefore, this is a login shell.

prompt> echo $0
bash # "-" is NOT the first character. This is NOT a login shell.

A shell started in a new terminal in a GUI would be an interactive non-login shell. It would source your .bashrc, but not your .profile, for example.

我的问题,得到圆满解决。
应当将export SMARTY_DIR=/usr/local/lib/Smarty/写进 ~/.bashrc 或者/etc/bash.bashrc

当然,最妥善的解决办法:
将export SMARTY_DIR=/usr/local/lib/Smarty/写入/etc/profile (满足login shell);    
同时將export SMARTY_DIR=/usr/local/lib/Smarty/寫入/etc/bash.bashrc(满足non-login shell)

理由如上。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号