Introduction to shell programming environment variable configuration files

1. Introduction to environment variable configuration files

1. Variable type

(1) User-defined variables (local variables)

(2) Environmental variables

(3) Predefined variables

(4) Position parameter variable

2. The source command

  • source configuration file <===>. configuration file

    • Reload configuration file

    ps: After modifying the configuration file, you must log out and log in again to take effect. Use the source command to avoid logging in

3. Introduction to environment variable configuration files

  • PATH, HISTSIZE, PS1, HOSTNAME and other environment variables are written into the corresponding environment variable configuration file

  • The environment variable configuration file mainly defines system default environment variables that take effect on the operating environment of the system, such as PATH.

4. Commonly used environment variable files

Works for all users

/etc/profile

/etc/profile.d/*.sh

/etc/bashrc

Act on the corresponding logged in user

~/.bash_profile

~/.bashrc


Second, the function of the environment variable configuration file

1. The login process

Insert picture description here

  • (1) The normal login process of the system

  • (2) Do not enter login, or switch to other users as root /etc/bashrc >> /etc/profile.d/*.sh >>/etc/profile.d/lang.sh >> /etc/sysconfig/i18n

2, the role of /etc/profile

	USER变量:

	LOGNAME变量:

	MAIL变量:

	PATH变量:
	
	HOSTNAME变量:

	HISTSIZE变量:

	umask:

	调用 /etc/profile.d/*sh 文件

3. The role of ~/.bash_profile

  • (1) The ~/.bashrc file is called

  • (2) The directory ":$HOME/bin" is added after the PATH variable

4. The role of /etc/bashrc

	PS1变量

	umask

	PATH变量

	调用/etc/profile.d/*.sh文件

5, umask instruction

  • umask View system default permissions

  • note:

    • (1) The highest file authority is 666

    • (2) The highest authority of the directory is 777

    • (3) Permissions cannot be converted by numbers, but letters must be used

    • (4) The permissions defined by umask are the permissions to be discarded in the system default permissions


Three, other configuration files

1. The environment variable configuration file that takes effect when logging off

  • ~/.bash_logout

    退出登陆,自动执行里面的命令
    
    Ps:如果再命令中输入明文的用户名和密码,建议清除历史命令
    

2. Other configuration files

  • (1)~/.bash_history

  • (2) Local terminal welcome message: /etc/issue

	转义符				作用

		\d			显示当前系统日期
		\s			显示操作系统名称
		\l			显示登录的终端号,这个比较常用
		\m			显示硬件体系结构,如i386、i686等
		\n			显示主机名
		\o			显示域名
		\r			显示内核版本
		\t			显示当前系统时间
		\u			显示当前登录用户的序列号
  • (3) Remote terminal welcome message: /etc/issue.net

    Escape characters cannot be used in the /etc/issue.net file

    Whether to display the welcome message is determined by the ssh configuration file /etc/ssh/sshd_config, and it can be displayed only by adding the "Banner /etc/issue.net" line (remember to restart the ssh service)

  • (4) Welcome message after login: /etc/motd

    This welcome message can be displayed regardless of remote login or local login

Guess you like

Origin blog.csdn.net/weixin_43272542/article/details/109541161