R0n9

声明:本人文章均为网上复制,用于检验本人电脑键盘录入、屏幕显示的机械、光电性能。并不代表本人局部或全部同意、支持或者反对观点。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

工作中遇到这样的问题,服务器上需要从root切换至postgreSQL安装用户去启动postgreSQL服务。

切换用户和启动postgreSQL命令如下:

# 切换至pgsql用户
su postgres
# 启动
pg_ctl start

-bash: pg_ctl: command not found

提示pg_ctl命令不存在,但是可以肯定的是之前安装postgreSQL时就是这么启动的,怎么这次不行了呢。

后来了解到原来是su命令的问题,有没有横杠"-"是有区别的。

su - postgres

有横杠login shell:用户切换,更改工作目录,加载所有用户环境配置。

无横杠interactive shell:用户切换,但是工作目录不会切换到该用户所在工作目录,也不会加载该用户设置的环境变量。

 

"When Bash starts executes the commands in a variety of different scripts.
(1) When started as an interactive login shell: Bash reads and executes the /etc/profile (if it exists). After reading that file, it looks for
~/.bash_profile, ~/.bash_login, and ~/.profile in that order, and reads and executes the first one (that exists and is readable).  When a login shell
exits: Bash reads and executes ~/.bash_logout (if it exists)。

(2) When started as an interactive shell (but not a login shell): Bash reads and executes ~/.bashrc (if it exists)."

posted on 2015-05-18 11:08  R0n9  阅读(1533)  评论(0编辑  收藏  举报