四时宝库

程序员的知识宝库

Linux编程Shell之入门——Shell配置文件

Shell 的配置文件主要有以下几个:

  1. /etc/profile:系统环境变量的系统级配置文件,对整个系统的用户都生效。
  2. /etc/bashrc:bash shell 的系统级配置文件,对整个系统的用户都生效。
  3. ~/.bash_profile:当前用户的用户级配置文件,对当前用户生效。
  4. ~/.bashrc:当前用户的用户级配置文件,对当前用户生效。

上述四个文件都是纯文本文件,在用户登陆时或打开新的终端时会被加载并执行。

其中,/etc/profile 和 /etc/bashrc 通常被用于设置系统级别的环境变量及全局的 bash 配置,而 ~/.bash_profile 和 ~/.bashrc 主要用于用户级别的环境变量及个人 bash 配置。

在这些配置文件中,可以设置 Shell 的别名、环境变量、shell 函数、PATH 等相关配置信息,以便用户自定义 Shell 的行为。在配置之后需要执行 source 命令或者重新启动终端才能生效。

当然,系统管理员为了管理方便,或者个性化,可以在系统的profile,或者用户自己的bashrc进行设置。

比如:某些全局性的应用配置环境,就可以直接定义在profile.或者bashrc


# .bashrc

# Source global definitions

if [ -f /etc/bashrc ]; then

. /etc/bashrc

fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:

# export SYSTEMD_PAGER=

# User specific aliases and functions

. /public/ibm/lsf10/conf/profile.lsf

export PATH=/public/tools:$PATH

# User specific aliases and functions

#modules

export PATH=/public/app/tool/modules/bin:$PATH

export MODULEPATH=/public/app/tool/modules/modulefiles:$MODULEPATH


#ENV

. /public/software/profile.d/compiler_intel-compiler-2017.5.239.sh

. /public/software/profile.d/mpi_intelmpi-2017.4.239.sh

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言
    友情链接