Overwriting the original PATH causes the command to fail to prompt command not found

  • 2021-01-03 21:14:36
  • OfStack

A colleague asked me to help him locate, why his LINUX server many commands can not be used, prompt (command not found), and more importantly, many system services, scripts can not run. What did you do before? He said, "What do you do?" but he added export PATH to the /etc/profile file. "How do you set it?" The answer is:


[root@localhost ~]# vim /etc/profile 
export PATH=/usr/lib/jenkins/
[root@localhost ~]# source /etc/profile 

He said he simply added jenkins's default working directory and then used source to make the configuration file work. That's exactly the problem!

PATH is the system environment path. All commands of the system and script execution are searched according to the path of PATH. But if the export PATH=/usr/lib/jenkins/ , take the directory set by the previous system, such as (/bin/; /sbin and other directories to store system commands) all covered, became jenkins work command, and jenkins directory is certainly can not find ls, pwd, cd and other system commands, the result of all the commands, scripts, services can not run, this is the main reason for this blood case!

How do you set up the real system PATH?

If the setting is short term:


export PATH=$PATH:/usr/lib/jenkins/

If it is a long-term setting:


[root@localhost ~]# vim /etc/profile 
export PATH=$PATH:/usr/lib/jenkins/
[root@localhost ~]# source /etc/profile

In this case, the new search path is added to the original Settings without overwriting the original PATH.

conclusion


Related articles: