Understanding Environment variables
Environment variables are simply a kind of storage location managed by the operating system. When you open a command prompt, you can see a list of environment variables by typing Set and pressing Enter. Figure 10-6 shows the environment variables on my system. The environment variables (or at least their values) will differ on your machine, so you should take a look at them. If you want to see the value of a particular environment variable, type Set VariableName (such as Set USERNAME) and press Enter. To remove an environment variable, simply type Set VariableName= (with no value) and press Enter. (Never remove environment variables you didn't create because some of your applications could, or more likely will, stop working.)
- SoLU-cé üode\G}iapterí8>Set 11.I.UKKftÜPROFI I.fc C:S.ll.1 «:«mtri(t!i and SettirigsNflli Users flPPÜfi I fi-C:\Documents and SettingsNJohnSfipplication Data CLiENrMflMf^ConsoJe Common ProgramFiles=C:'sProgram Files ^Common Files GOMPU uyÍNflME-Mfll N
ComSpec =C: MJ1NDOWSSs ystem32\cmd.exe
PI* NO HOST CHECK-HO
HOMEDRIUE-C;
HOMEPflTH=NDocurients and SettingsNJohn F ROWPVTHONPfi TH =6:: \Python2G\L i h LOGONS ERUÍLR=\N1ÍA IN NUMBER_OF_PROCESSORK=1 OS =U i n do vis. ..NT
Pa t h: \U í M L"0UE \s ys t fi i«3 5!; C: MJ1 NDOWS ;C:\U]HDOWSys t e m3 2\Ube m;C:\Pro g ram Filss\Mi crosoft SQL SeruerM 38\Too ls\Binn\; C: \Program FilessMicrcsoft SQL Sei"jer\i80\DTS \Einn\;C:\Program FilesNMir.rosoft: SQL Seruer\l(3ei\Too ls\!fi inn\USSlte il\Coiimon7\I DE\ ;C:\Program Fí iesNMicrosoft Uisual Sturii» 9, H\Conirion7"\IDE\PriiPa1;efissemblies\;C:\ SHNDOHS\system32MJisidowsPo«erSitell\ui.0; C:\Pro gram FilesSJaua\jdki .6 .£)_16\b:in ;C: "sProgram File sSI ronPytíion 2.G
PiiiHEHI-.COtf; .EXE; .íifií ; .CMD;.UBS; .URE;.JS;.JSE;.WSF; .USH;. PSCi PROGES SOÍi fi BCH > IECT URE=x8 6
PROCESSOR I DENT I FI ER=x86 Family 15 Model 47 Stepping 0, iluthent icflHD
PROCESSOR LEUHt/=i5
ProgramFiIe5=C:SProgram Files
SystemDrive-C:
GystemRoot =C:\W1 NDOUS
IEHP -C: \f)0Cli \ J o }¡n \L0Cfl LS "1 \T e up ri1P=G: «íjJOCUME^ \john\tOCfiLS"!\Tttnis
¡JSERDOMfti N-flfii N
LÍSÉRNflME=John
JSERPROFI I.i 'OVNBtocurHtrtés ami Se tt i ngs\Jolin
IJÜ1S0COMNTOOLS -=C:NProgram Fí lesSMicrosof t Uisual Studiü í S.8\Gommí>n?\Tools\ US98C0MNT00LS =C:SProgram Files^Microsoft Uisual Studio 9.0SCommon7\Tools\ uindir=C:\l!iNDOUS
C:\B255 - Source Gode\C)iapterl0> Z
FIGURE 10-6: Most computers have a wealth of environment variables.
As you can see from Figure 10-6, environment variables appear as a name/value pair. An environment variable with a specific name has a certain value. Some environment variables in this list are common to all Windows machines. For example, the system wouldn't be able to find applications without the Path environment variable. Environment variables such as COMPUTERNAME and USERNAME can prove helpful for your applications. You can also discover facts such as the processor type and system drive using environment variables.
It's possible to create environment variables using a number of techniques. However, the method used to create the environment variable determines its scope (personal or global), visibility (command prompt only or command prompt and Windows application), and longevity (session or permanent). For example, if you type Set MyVar=Hello (notice that there are no quotes for the value) and press Enter, you create a personal environment variable that lasts for the current session and is visible only in the command prompt window. You can see any environment variable by typing Echo %VarName% and pressing Enter. Try it out with MyVar. Type Echo %MyVar% and press Enter to see the output shown in Figure 10-7.
|
C:\WIN DDWS\5ystem 3 2\c m d. exe |
_ □ X |
|
C:\eaEi5 - Source Code\Chapterl0>ccho JiMyUarX 'Hello' |
Post a comment