Linux—environment variables

 

1. Commonly used environment variables

  • HOME: The current user's home directory
  • PS1: The basic prompt is # for root users and $ for ordinary users.
  • LOGNAME: the login name of the user at the time
  • PWD: current directory
  • MAIL: current user's mail storage directory
  • SHELL: current user shell type
  • PATH: Determines which directories the shell will search for commands or directories
  • TERM: terminal type
  • HOSTNAME: The name of the current host
  • LANG: Current language.

2. Commonly used environment variable commands

  1. echo: The user displays the value of an environment variable.
    如:echo $HOME

     

  2. env: Display all environment variables, including system environment variables and custom environment variables.
  3. set: You can set the value of an environment variable.
  4. export: Set a new environment variable.
    export MYSQL=‘/usr/local/mysql’  #设置临时环境变量;
    env|grep MYSQL      #此命令有输出说明环境变量MYSQL存在了;
    关掉命令行,环境变量即消除。
    

     

  5. unset: Clear environment variables.
    unset $MYSQL   #删除环境变量MQSQL
    env|grep MYSQL  #此命令没输出,说明环境变量被清除了
    

     

  6. readonly: Set the environment variable to read-only.
    export MYSQL=‘/usr/local/mysql’  #设置临时环境变量;
    readonly MYSQL     #将环境变量MYSQL设置为只读
    unset MYSQL     #发现此变量不能被删除
    MYSQL=‘/usr/local/XX’      #此变量也不能被修改
    

     

3. Environment Variable File

  Divided by the life cycle of variables, Linux variables can be divided into two categories: 
      permanent: the configuration file needs to be modified, and the variable takes effect permanently. 
      Temporary: Just use the export command to declare, the variable becomes invalid when the shell is closed.

  The environment variable files in Linux include:     

  1. /etc/profile is effective for all users [permanent] 
  2. /ect/bashrc 
  3. ~/.bash_profile Effective for a single user [permanent] Generally, the environment variables added by yourself are placed in this file. 
    cat .bash_profile     #显示环境变量
    vim .bash_profile       #编辑此环境变量文件
    source .bash_profile    #修改文件后,运行该命令修改马上生效,不然只能在下次重新进入此用户时生效。
    

     

  4. ~/.bashrc
  5. ~/.bash_logout

              

Guess you like

Origin blog.csdn.net/zpy20120201/article/details/90344622