Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CentOS environment variable setting

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Method 1: add a variable to the / etc/profile file [effective for all users (permanent)]

Add a variable to the file / etc/profile file with VI, which will be valid for all users under Linux and will be "permanent". [root@CentOS ~] # vi / etc/profile add the following two lines of code PATH=/usr/local/webserver/php/bin:$PATHexport PATH # / etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in / etc/bashrc# It's NOT a good idea to change this file unless you know what you# are doing at the end of the file. It's much better to create a custom.sh shell script in# / etc/profile.d/ to make custom changes to your environment, as this# will prevent the need for merging in future updates.pathmunge () {case ": ${PATH}:" in *: "$1": *); *) if ["$2" = "after"] Then PATH=$PATH:$1 else PATH=$1:$PATH fi esac} if [- x / usr/bin/id]; then if [- z "$EUID"]; then # ksh workaround EUID= `id-u`UID= `id-ru`fi USER= "`id-un`" LOGNAME=$USER MAIL= "/ var/spool/mail/$USER" fi# Path manipulationif ["$EUID" = "0"] Then pathmunge / sbin pathmunge / usr/sbin pathmunge / usr/local/sbinelse pathmunge / usr/local/sbin after pathmunge / usr/sbin after pathmunge / sbin afterfiHOSTNAME= `/ bin/hostname 2 > / dev/ null`HISTSIZE = 1000if ["$HISTCONTROL" = "ignorespace"]; then export HISTCONTROL=ignorebothelse export HISTCONTROL=ignoredupsfiexport PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL# By default, we want umask to get set. This sets it for login shell# Current threshold for system reserved uid/gids is 20 You could check uidgid reservation validity in# / usr/share/doc/setup-*/uidgid fileif [$UID-gt] & & ["`id-gn `" = "`id-un`"]; then umask 002else umask 022fifor I in / etc/profile.d/*.sh; do if [- r "$I"]; then if ["${- # * I}"! = "$-"] Then. "$I" else. "$I" > / dev/null 2 > & 1 fi fidoneunset iunset pathmunge PATH=/usr/local/webserver/php/bin:$PATH export PATH if the changes just made take effect immediately, you need to execute the following code [root@CentOS ~] # source / etc/profile method 2: add variables to the. bash_profile file in the user directory [effective for a single user (permanent)] use VI to add variables to the. bash_profile file in the user directory The change is valid only for the current user and is "permanent". The specific operation is the same as method 1, so the code is not enumerated here. Method 3: directly run the export command to define the variable [valid for the current shell (BASH) only (temporary)] under the command line of shell, directly use [export variable name = variable value] to define the variable, the variable is only valid under the current shell (BASH) or its child shell (BASH), shell is closed, the variable is invalid, and then open the new shell without this variable, you need to redefine it if you need to use it. For example, export PATH=/usr/local/webserver/php/bin:$PATH

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report