Environment variable
来源:互联网 发布:qq三国79js奥义三板斧 编辑:程序博客网 时间:2024/04/26 06:58
fork
and exec
. Alternatively, from command shells such as bash, a user can change environment variables for a particular command invocation by indirectly invoking it viaenv
or using the ENVIRONMENT_VARIABLE=VALUE <command>
notation. AllUnix operating system flavors, DOS, and Windows have environment variables; however, they do not all use the same variable names. A running program can access the values of environment variables for configuration purposes.- PATH - a list of directory paths. When the user types a command without providing the full path, this list is checked to see whether it contains a path that leads to the command.
- HOME (Unix-like) and USERPROFILE (Microsoft Windows) - indicate where a user's home directory is located in the file system.
- HOME/{.AppName} (Unix-like) and APPDATA\{DeveloperName\AppName} (Microsoft Windows) - for storing application settings. Many applications incorrectly use USERPROFILE for application settings in Windows - USERPROFILE should only be used in dialogs that allow user to choose between paths like Documents/Pictures/Downloads/Music, for programmatic purposes APPDATA (roaming), LOCALAPPDATA or PROGRAMDATA (shared between users) is used.
- TERM (Unix-like) - specifies the type of computer terminal or terminal emulator being used (e.g., vt100 or dumb).
- PS1 (Unix-like) - specifies how the prompt is displayed in the Bourne shelland variants.
- MAIL (Unix-like) - used to indicate where a user's mail is to be found.
- TEMP - location where processes can store temporary files
COMMAND.COM
's existence.AUTOEXEC.BAT
file.$LD_LIBRARY_PATH
and$LD_PRELOAD
and run it with the process's authority. If a setuid program did this, it would be insecure, because its caller could get it to run arbitrary code and hence misuse its authority. For this reason, libc unsets these environment variables at startup in a setuid process. setuid programs usually unset unknown environment variables and check others or set them to reasonable values.echo $HOME
In DOS, OS/2 and Windows command-line interpreters such as COMMAND.COM
andcmd.exe
, the user has to type this:
ECHO %HOME%
In Windows PowerShell, the user has to type this:
Write-Output $env:HOMEPATH
env
, set
, and printenv
display all environment variables and their values. printenv
can also be used to print a single variable by giving that variable name as the sole argument to the command.Unix[edit]
In Unix, the following commands can also be used, but are often dependent on a certain shell.
VARIABLE=value #export VARIABLE # for Bourne and related shells
export VARIABLE=value # for ksh, bash, and related shells
setenv VARIABLE value # for csh and related shells
export
keyword. Variables defined in this way are displayed by theset
command, but are not true environment variables, as they are stored only by the shell and not recognized by the kernel. The printenv
command will not display them, and child processes do not inherit them.VARIABLE=value
However, if used in front of a program to run, the variables will be exported to the environment and thus appear as real environment variables to the program:
VARIABLE=value program_name [arguments]
.profile
or .bashrc
or your current shell profile file (located in your home directory). Then, each time you open your shell it will be loaded.To change the environmental variable "permanently" you'll need to consider at least these situations:
- Login/Non-login shell
- Interactive/Non-interactive shell
bash
- Bash as login shell will load
/etc/profile
,~/.bash_profile
,~/.bash_login
,~/.profile
in the order - Bash as non-login interactive shell will load
~/.bashrc
- Bash as non-login non-interactive shell will load the configuration specified in environment variable
$BASH_ENV
$EDITOR ~/.bashrc#add lines at the bottom of the file: export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib export ORACLE_HOME=/usr/lib/oracle/11.2/client64
zsh
$EDITOR ~/.zshrc#add lines at the bottom of the file: export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib export ORACLE_HOME=/usr/lib/oracle/11.2/client64
ksh
$EDITOR ~/.profile#add lines at the bottom of the file: export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib export ORACLE_HOME=/usr/lib/oracle/11.2/client64
bourne
$EDITOR ~/.profile#add lines at the bottom of the file: LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib ORACLE_HOME=/usr/lib/oracle/11.2/client64 export LD_LIBRARY_PATH ORACLE_HOME
csh or tcsh
$EDITOR ~/.login#add lines at the bottom of the file: setenv LD_LIBRARY_PATH /usr/lib/oracle/11.2/client64/lib setenv ORACLE_HOME /usr/lib/oracle/11.2/client64
/etc/profile
or /etc/environment
.DOS, OS/2 and Windows[edit]
In DOS, OS/2 and Windows command-line interpreters such as COMMAND.COM
andcmd.exe
, the SET
command is used to assign environment variables and values using the following arguments:
SET VARIABLE=value
SET
command without any arguments displays all environment variables along with their values. - Environment variable
- Configure the environment variable
- My shell environment variable
- The CATALINA_HOME environment variable
- The http_proxy Environment Variable
- reading environment variable python
- Oracle:environment variable "PATH"
- PYTHONPATH environment variable
- Request.ServerVariables (server environment variable)
- linux java environment variable configure
- [DOS]Delayed environment variable expansion
- Environment variable ORACLE_UNQNAME not defined
- how to java --->environment variable
- Define environment variable in LINUX
- DISPLAY environment variable not set!
- environment variable 'STAGING_DIR' not defined
- Configure Java environment variable in debian 5.0
- 环境变量(Environment Variable)那点事
- LeetCode 155 Min Stack(最小栈)
- Qt中文件类型过滤器
- NavigationController的视图,滑动手势返回
- 【黑马程序员】Foundation框架(四)
- 汇编除法运算
- Environment variable
- MySql触发器
- Java SE,Java EE ,Java ME 区别
- 【Android】startActivityForResult与startActivity
- 匿名对象
- hdu 2200 Eddy's AC难题
- hdu 2563(递推)
- Android TextView setGravity不起作用
- C++ 程序设计 week 5 继承和派生