What Are Environment Variables?
Environment Variables are stored in a small area of memory available to all programs running within or on top of the DOS environment (including Windows). They are called “variables” because they can be changed. In fact, some variables need to be reestablished after every reboot. For the Ruby language, Facter stores and retrieves "facts" from operating systems. | Related: |
|
Windows System Environment VariablesThese system environment variables are automatically created by Windows upon boot-up in Windows Registry key HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Control\ Session Manager\ Environment
If you have the permissions, invoke, then open my DOS batch file 1envvars.bat which lists the values of these variables on your computer
Windows resolves commands typed in the start/run box first from files
in Below are dynamic environment variables: |
|
Variable | Sample Typical Value |
---|---|
%CD% | The current directory. |
%DATE% | Current date in the format set by the Date command |
| Current time in the format set by the Time command |
%ERRORLEVEL% | A number defining exit status of a previous command or called executable. |
%RANDOM% | A random number between 0 and 32767. |
You can quickly reach the folder specified within an environment variable by typing that variable on the Address bar of Windows Explorer:
User Environment Variables Added by ApplicationsUser environment variables are stored in Windows Registry HKEY_CURRENT_USER\Environment Within a command batch file, to list Oracle Environment Variables echo ORACLE_SID = %ORACLE_SID% echo ORACLE_HOME = %ORACLE_HOME% echo ORA_NLS = %ORA_NLS% echo. echo PATH = %PATH% echo. echo Machine Name to messenger service: net name Novell adds these environment variables during installation.
|
|
Creating Variables on Windows
|
|
UNIX Environment Variables
In UNIX/Linux systems, add a dollar sign ($) in front of each variable name in all caps:
In UNIX systems, the colon (:). In Windows systems, the semi-colon (;) is used. So to list each path in a separate line:
Solaris systems have additional ones, including:
|
Creating Variables on Linux
#echo $PATH Notice that colons are used to separate path items. To create an environment variable that lives forever, update your .bash_profile file:
export XXXPATH For a list of environment settings (arguments) for a process with PID 23141 (on Solaris):
|
|
Java Environment Variables
The Java interpreter searches the PATH for a class by name and loads the first one it finds. So specify your own library and the most recent library first (especially if you use the same name as a class in a standard library). Also, for best performance, place the most-often used libraries at the front of the path. This applies to LIBPATH and LD_LIBRARY_PATH variables for most often used JNI libraries. Java 1.4 Documentation on Classpath notes that the preferred method for command-line tools such as java, javac, or javadoc is to NOT use environment variables but instead specify -classpath as part of the command invoking a Java program. The System environment variable CLASSPATH must be in upper case (not “classpath”). CLASSPATH is used to specify the full path and file name of every jar file used by java programs. Thus CLASSPATH could be quite long. C:\jdk1.3.1_01\src.jar; C:\jdk1.3.1_01\lib\dt.jar; C:\jdk1.3.1_01\lib\tools.jar; C:\jdk1.3.1_01\jre\lib\il8n.jar; C:\jdk1.3.1_01\jre\lib\jaws.jar; C:\jdk1.3.1_01\jre\lib\rt.jar; C:\jdk1.3.1_01\jre\demo\sound\JavaSound.jar; C:\jdk1.3.1_01\demo\jfc\SwingSet2\SwingSet2.jar; C:\jdk1.3.1_01\demo\jfc\SwingApplet\SwingApplet.jar; Sun's JDK adds:
C:\jdk1.3.1_01\Bin; C:\jdk1.3.1_01\Lib; A common mistake with CLASSPATH is to specify only folder paths and leave out jar file names. Semicolons should separate each jar file specification. On client machines, Microsoft's VM CLASSPATH is, by default:
This string is stored in environment variable CLASSPATH or Windows registry key
Windows 95/98 computers should limit CLASSPATH to less than 400 characters. Dick Baldwin notes in his tutorial that if you want the CLASSPATH to point to class files that belong to a package, you should specify a path name that includes the path to the directory one level above the directory having the name of your package. For example, suppose you want the Java interpreter to be able to find classes in the package mypackage. If the path to the mypackage directory is C:\java\MyClasses\mypackage, you would set the CLASSPATH variable as follows:
set CLASSPATH=C:\java\MyClasses
The purpose of the package directive is to identify a particular class (or group of classes contained in a single source file (compilation unit)) as belonging to a specific package. NOTE: Training connection also offers some great tutorials on Java programs, Dreamweaver training, and Flex software. In Linux: pCLASSPATH=/usr/local/java/jre/bin My CLASSPATH: |
|
Amazon EC2 File PathsAmazon EC2 command script users add these environment variables. For example, if EC2 files are located in folder C:\EC2:
|
|
Windows Network Shares
Changes to variables disappear after reboot.
... This assumes that the loopback IP address has not been changed in the hosts file. |
|
Microsft T-SQL to Read Windows environment variablesTo read Windows environment variables using Microsoft SQL Server T-SQL code: -- Display all environment variables EXEC master..xp_cmdshell 'set' ------------ -- Retrieve a single environment variable - Read environment variable DECLARE @EnvVar nvarchar(256) CREATE TABLE #Upload(EnvVar nvarchar(256)) INSERT INTO #Upload EXEC xp_cmdshell 'echo %USERDOMAIN%' DELETE #Upload WHERE EnvVar is NULL OR EnvVar = '' SET @EnvVar = (SELECT EnvVar from #Upload) SELECT @EnvVar as [User Domain] /* User Domain ENTERPRISE */ DROP TABLE #Upload Source: sqlusa.com |
|
| Your first name: Your family name: Your location (city, country): Your Email address: |
Top of Page
Thank you! |