python get environment variable
https://stackoverflow.com/questions/4906977/how-can-i-access-environment-variables-in-python
How can I access environment variables in Python?
2011-02-05T13:03:35Z
Amit YadavAmit Yadav 33.6k77 gold badges4343 silver badges6363 bronze badges
<html><body><div><div>
<p><strong>Edited - October 2021</strong></p>
<p>Following @Peter&#39;s comment, here&#39;s how you can test it:</p>
<p><code>main.py</code></p>
<pre><code>#!/usr/bin/env python
from os import environ
# Initialize variables
num_of_vars = 50
for i in range(1, num_of_vars):
 environ[f&#34;_BENCHMARK_{i}&#34;] = f&#34;BENCHMARK VALUE {i}&#34; 
def stopwatch(repeat=1, autorun=True):
 &#34;&#34;&#34;
 Source: https://stackoverflow.com/a/68660080/5285732
 stopwatch decorator to calculate the total time of a function
 &#34;&#34;&#34;
 import timeit
 import functools
 
 def outer_func(func):
 @functools.wraps(func)
 def time_func(*args, **kwargs):
 t1 = timeit.default_timer()
 for _ in range(repeat):
 r = func(*args, **kwargs)
 t2 = timeit.default_timer()
 print(f&#34;Function={func.__name__}, Time={t2 - t1}&#34;)
 return r
 
 if autorun:
 try:
 time_func()
 except TypeError:
 raise Exception(f&#34;{time_func.__name__}: autorun only works with no parameters, you may want to use @stopwatch(autorun=False)&#34;) from None
 
 return time_func
 
 if callable(repeat):
 func = repeat
 repeat = 1
 return outer_func(func)
 
 return outer_func
@stopwatch(repeat=10000)
def using_environ():
 for item in environ:
 pass
@stopwatch
def using_dict(repeat=10000):
 env_vars_dict = dict(environ)
 for item in env_vars_dict:
 pass
</code></pre>
<pre><code>python &#34;main.py&#34;
# Output
Function=using_environ, Time=0.216224731
Function=using_dict, Time=0.00014206099999999888
</code></pre>
<p>If this is true ... It&#39;s 1500x faster to use a <code>dict()</code> instead of accessing <code>environ</code> directly.</p>
<hr/>
<p>A performance-driven approach - calling <code>environ</code> is expensive, so it&#39;s better to call it once and save it to a dictionary. Full example:</p>
<pre><code>from os import environ
# Slower
print(environ[&#34;USER&#34;], environ[&#34;NAME&#34;])
# Faster
env_dict = dict(environ)
print(env_dict[&#34;USER&#34;], env_dict[&#34;NAME&#34;])
</code></pre>
<p>P.S- if you worry about exposing private environment variables, then sanitize <code>env_dict</code> after the assignment.</p>
 </div></div></body></html>
Edited - October 2021 
Following @Peter&#39;s comment, here&#39;s how you can test it:
 main.py 
 #!/usr/bin/env python
from os import environ
# Initialize variables
num_of_vars = 50
for i in range(1, num_of_vars):
 environ[f&#34;_BENCHMARK_{i}&#34;] = f&#34;BENCHMARK VALUE {i}&#34; 
def stopwatch(repeat=1, autorun=True):
 &#34;&#34;&#34;
 Source: https://stackoverflow.com/a/68660080/5285732
 stopwatch decorator to calculate the total time of a function
 &#34;&#34;&#34;
 import timeit
 import functools
 
 def outer_func(func):
 @functools.wraps(func)
 def time_func(*args, **kwargs):
 t1 = timeit.default_timer()
 for _ in range(repeat):
 r = func(*args, **kwargs)
 t2 = timeit.default_timer()
 print(f&#34;Function={func.__name__}, Time={t2 - t1}&#34;)
 return r
 
 if autorun:
 try:
 time_func()
 except TypeError:
 raise Exception(f&#34;{time_func.__name__}: autorun only works with no parameters, you may want to use @stopwatch(autorun=False)&#34;) from None
 
 return time_func
 
 if callable(repeat):
 func = repeat
 repeat = 1
 return outer_func(func)
 
 return outer_func
@stopwatch(repeat=10000)
def using_environ():
 for item in environ:
 pass
@stopwatch
def using_dict(repeat=10000):
 env_vars_dict = dict(environ)
 for item in env_vars_dict:
 pass
 
 python &#34;main.py&#34;
# Output
Function=using_environ, Time=0.216224731
Function=using_dict, Time=0.00014206099999999888
 
If this is true ... It&#39;s 1500x faster to use a dict() instead of accessing environ directly.
A performance-driven approach - calling environ is expensive, so it&#39;s better to call it once and save it to a dictionary. Full example:
 from os import environ
# Slower
print(environ[&#34;USER&#34;], environ[&#34;NAME&#34;])
# Faster
env_dict = dict(environ)
print(env_dict[&#34;USER&#34;], env_dict[&#34;NAME&#34;])
 
P.S- if you worry about exposing private environment variables, then sanitize env_dict after the assignment.
How can I access environment variables in Python?
https://stackoverflow.com/questions/4906977/how-do-i-access-environment-variables-in-python
https://stackoverflow.com/questions/67194339/how-do-you-access-environment-variable-values-without-os
How do you access environment variable values without os?
2021-04-21
James Geddes James Geddes
<div><div>
 
<div>
 
 
<div>
 
 <div>
 
<p>Using <code>os</code> code is generally accepted as bad practice from a security perspective, as it could potentially provide a <a href="https://www.assured.enterprises/company/cybersecurity-resources/glossary/#firstcontentcontainer:%7E:text=Bad%20Actor,-%E2%80%94A">bad actor</a> with <a href="https://www.youtube.com/watch?v=SfTfXLLJlzM">phenomenal cosmic powers</a>. Nonetheless, most sources appear to recommend using the following to get <code>env</code> variables.</p>
<pre><code>import os
print(os.environ['FOO'])
</code></pre>
<p>This approach is also suggested here on SO, such as in "<a href="https://stackoverflow.com/questions/4906977/how-to-access-environment-variable-values">How to access environment variable values?</a>" I know that one can use <a href="https://pypi.org/project/python-dotenv/">dotenv</a> to pick up a <code>.env</code> file and to create new <code>env</code> variables, but I have not been able to find anything for existing <code>env</code> variables.</p>
<p>This leads me to the following questions.</p>
<ul>
<li>Is Python's <code>os</code> secure enough to render my concerns unnecessary?</li>
<li>Is <code>from os import environ</code> any better than going for the entire <code>import os</code>?</li>
<li>Is there a method that is more secure and avoids <code>os</code> entirely?</li>
</ul>
<p>Thanks muchley!</p>
 </div>
 
 <div>
 
 <div>
 <a href="/users/1968/konrad-rudolph"><p></p></a>
 </div>
 <div>
 <p>
 asked Apr 21, 2021 at 10:48
 </p>
 <div>
 <a href="/users/4162689/james-geddes"><p></p></a>
 </div>
 
</div>
 </div>
 
</div>
 <p>6</p>
 </div>
 <div>
 
 
<div>
 
 
<div>
 
 <div>
<blockquote>
<p>I was saying that, in general, it is advised to avoid using operating system code for security reasons.</p>
</blockquote>
<p>That is not true. Even if by "os code" you mean only Python's <code>os</code> module and not system calls (see the output of <code>man 2</code> on a UNIX system). You should stop reading (or watching) whatever gave you that impression.</p>
<p>There are a handful of functions which can pose a security risk if used incorrectly. The most notorious being <code>os.popen()</code> when passed a single string as the command to run. When used in that manner the string is interpreted by a subshell and is subject to "word expansion" and "word splitting". Which, in a POSIX shell like bash, is risky unless you are 100% certain about any shell metacharacters that might be present in the original string or the values of any variable expansions.</p>
<p>There is absolutely nothing risky about <code>os.environ</code> other than the exception that will be raised if the key (the env var name) is not present in the map. Which is why you should generally use <code>os.getenv()</code> since that makes it easier to handle the case where the env var isn't present.</p>
 </div>
 <div>
 <p>
 answered Apr 21, 2021 at 19:42
 </p>
 <div>
 <a href="/users/4276647/kurtis-rader"><p></p></a>
 </div>
 <div>
 <p><a href="/users/4276647/kurtis-rader">Kurtis Rader</a>Kurtis Rader</p><p>6,24211 silver badges16 bronze badges
 </p>
 </div>
</div>
 
</div>
 <p>3</p>
 </div>
 
 <h2>
 
 </h2>
 </div>
 </div>||||I|||| Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. Home
 2. 
 1. Public
 2. Questions
 3. Tags
 4. Users
 5. Companies
 6. Collectives
 7. Explore Collectives
 3. 
 1. Teams
 Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
 2. Teams
 3. Create free Team

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 How do you access environment variable values without os?

 Ask Question
 Asked 1 year, 9 months ago
 Modified 1 year, 9 months ago
 Viewed 866 times
 2

 Using os code is generally accepted as bad practice from a security perspective, as it could potentially provide a bad actor with phenomenal cosmic powers. Nonetheless, most sources appear to recommend using the following to get env variables.

 import os
 print(os.environ['FOO'])
 

 This approach is also suggested here on SO, such as in "How to access environment variable values?" I know that one can use dotenv to pick up a .env file and to create new env variables, but I have not been able to find anything for existing env variables.

 This leads me to the following questions.

 * Is Python's os secure enough to render my concerns unnecessary?
 * Is from os import environ any better than going for the entire import os?
 * Is there a method that is more secure and avoids os entirely?

 Thanks muchley!

 * python
 * python-3.x
 * security
 * environment-variables
 Share
 Improve this question
 Follow
 edited Apr 21, 2021 at 10:54
 Konrad Rudolph
 521k 128 128 gold badges 926 926 silver badges 1205 1205 bronze badges
 asked Apr 21, 2021 at 10:48
 James Geddes James Geddes
 692 3 3 gold badges 9 9 silver badges 33 33 bronze badges
 6
 * 3
 I'm sorry, why do you want to avoid os? Where is it generally accepted as bad practice? It's probably imported already just as part of the interpreter runtime. I'm not sure what you are trying to avoid, exactly.
 – juanpa.arrivillaga
 Apr 21, 2021 at 10:54
 * 3
 "Is from os import environ any better than going for the entire import os?" why would it be? Note, you cannot "partially" import modules, these two different import statements merely change what is made available in the current namespace... the module is fully loaded in either case
 – juanpa.arrivillaga
 Apr 21, 2021 at 10:55
 * 4
 There are parts of os that may be risky (such as the os.exec family) if you don't use them properly. But environment variables are no more risky that user input.
 – paxdiablo
 Apr 21, 2021 at 10:56
 * @juanpa.arrivillaga I am not saying that Python's os specifically is bad, I was saying that, in general, it is advised to avoid using operating system code for security reasons. Whether this extends to Python's os is the aim of this question.
 – James Geddes
 Apr 21, 2021 at 11:06
 * 1
 The os module isn't operating system code. It's Python code. It has that name because it provides access to facilities that are provided by the operating system or the shell. You are reading way too much into the way it is named.
 – BoarGules
 Apr 21, 2021 at 21:08
 | Show 1 more comment

 1 Answer

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 1

 I was saying that, in general, it is advised to avoid using operating system code for security reasons.

 That is not true. Even if by "os code" you mean only Python's os module and not system calls (see the output of man 2 on a UNIX system). You should stop reading (or watching) whatever gave you that impression.

 There are a handful of functions which can pose a security risk if used incorrectly. The most notorious being os.popen() when passed a single string as the command to run. When used in that manner the string is interpreted by a subshell and is subject to "word expansion" and "word splitting". Which, in a POSIX shell like bash, is risky unless you are 100% certain about any shell metacharacters that might be present in the original string or the values of any variable expansions.

 There is absolutely nothing risky about os.environ other than the exception that will be raised if the key (the env var name) is not present in the map. Which is why you should generally use os.getenv() since that makes it easier to handle the case where the env var isn't present.

 Share
 Improve this answer
 Follow
 answered Apr 21, 2021 at 19:42
 Kurtis Rader Kurtis Rader
 6,242 11 11 silver badges 16 16 bronze badges
 3
 * My impression on operating code was formed by my IBM Cybersecurity qualification credly.com/badges/6bf9b2a9-604f-4bcd-b319-127afc4a051e/… but as I mentioned, the purpose of this question is to learn whether that extends to the Python os module.
 – James Geddes
 Apr 22, 2021 at 8:30
 * @JamesGeddes: In my four decades as an IT professional I've received numerous certifications and accreditations such as the one you cite. In my experience most of them aren't worth the paper they're printed on. Again, there is nothing risky about "operating system code" or Python's os module; at least in the broad sense you mean.
 – Kurtis Rader
 Apr 22, 2021 at 18:00
 * I am glad my concerns are unwarranted in this case. Seems sensible to avoid unnecessary security risks in general though.
 – James Geddes
 Apr 23, 2021 at 9:43
 Add a comment |

 Your Answer

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

 Not the answer you're looking for? Browse other questions tagged
 * python
 * python-3.x
 * security
 * environment-variables
 or ask your own question.

 * The Overflow Blog
 * Announcing more ways to learn and grow your skills
 * Why developer experience is the key to better software, straight from the...
 * Featured on Meta
 * Accessibility Update: Colors
 * 2022: a year in moderation
 * Collectives: The next iteration
 * We’re bringing advertisements for technology courses to Stack Overflow
 * Temporary policy: ChatGPT is banned

 Linked

 2988
 How can I access environment variables in Python?

 Related

 6891
 How do I check whether a file exists without exceptions?
 1669
 How can I make a dictionary (dict) from separate lists of keys and values?
 2347
 How to print without a newline or space
 1518
 How can I check for NaN values?
 3195
 How do I pass a variable by reference?
 2988
 How can I access environment variables in Python?
 1059
 How to set environment variables in Python?
 2180
 How do I delete an exported environment variable?
 3268
 How do I select rows from a DataFrame based on column values?
 1209
 How do I pass environment variables to Docker containers?

 Hot Network Questions

 * Other than looking cool as hell, what is the reason behind the TSR-2's anhedral wingtips?
 * Stable words in the Proto-Indo-European language family
 * Which country has the most Diplomatic Missions in another country?
 * Polynomial approximation of max function
 * How can one order cheeses for a cheese tasting event?
 * Sum of Consecutive Squares
 * A journal editor has pretended my referee report actually came from two separate referees
 * Lightning Field Labels displayed Inline for some Users
 * Is there a canonical name for a polynomial-like expression allowing for negative powers?
 * Isekai manga where the main character is a healer but gets his limbs chopped off
 * Find the perimeter (seemingly unsolvable problem)
 * Agile Principles: What does it mean sustainable development?
 * What did Paul McCartney mean by "Oh, yesterday came suddenly"?
 * Not Bruce Wayne! Carry On!
 * How to find the safest place to cross a frozen river from a map?
 * Why do Pokemon sometimes have dark stripes in Pokemon Go?
 * Fingering - Don't Stop Me Now - Peter Bence
 * Why is the solstice the first day of summer, and not the central day?
 * How can an Indian homemaker spouse be guaranteed a Schengen tourist visa?
 * Understanding how to terminate recurrence relations in quantum SHO
 * How would you say "mindless fun" in German
 * What changes to Voyager could have been made?
 * Smallest Bit Rotation
 * Can a vampire rest in a coffin in a bag of holding?
 more hot questions
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.2.6.43220

 Your privacy

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

 Accept all cookies Customize settings
Using os code is generally accepted as bad practice from a security perspective, as it could potentially provide a bad actor with phenomenal cosmic powers. Nonetheless, most sources appear to recommend using the following to get env variables.
 import os
print(os.environ['FOO'])
 
This approach is also suggested here on SO, such as in "How to access environment variable values?" I know that one can use dotenv to pick up a .env file and to create new env variables, but I have not been able to find anything for existing env variables.
This leads me to the following questions.
Is Python's os secure enough to render my concerns unnecessary?
Is from os import environ any better than going for the entire import os?
Is there a method that is more secure and avoids os entirely?
Thanks muchley!
 
 
 
 
 
    
 
 
 
 asked Apr 21, 2021 at 10:48
 
 
    
 
 
 
 
 6
 
 
 
 
 
 
 
 
I was saying that, in general, it is advised to avoid using operating system code for security reasons.
That is not true. Even if by "os code" you mean only Python's os module and not system calls (see the output of man 2 on a UNIX system). You should stop reading (or watching) whatever gave you that impression.
There are a handful of functions which can pose a security risk if used incorrectly. The most notorious being os.popen() when passed a single string as the command to run. When used in that manner the string is interpreted by a subshell and is subject to "word expansion" and "word splitting". Which, in a POSIX shell like bash, is risky unless you are 100% certain about any shell metacharacters that might be present in the original string or the values of any variable expansions.
There is absolutely nothing risky about os.environ other than the exception that will be raised if the key (the env var name) is not present in the map. Which is why you should generally use os.getenv() since that makes it easier to handle the case where the env var isn't present.
 
 
 
 answered Apr 21, 2021 at 19:42
 
 
    
 
 
  Kurtis RaderKurtis Rader 6,24211 silver badges16 bronze badges
 
 
 
 3
How do you access environment variable values without os?
https://stackoverflow.com/questions/67194339/how-do-you-access-environment-variable-values-without-os
https://stackoverflow.com/questions/69655671/how-to-get-environment-variable-in-python-subprocess
How to get environment variable in python subprocess
2021-10-21
Tinyden Tinyden
<div><div>
<div>
<div>
<div>
<p>I have a driver program which launches and manages hundreds of processes by</p>
<pre><code>p = subprocess.Popen(cmd)
</code></pre>
<p>One of the situation I'm facing with is:
since many processes may set-up their own environment variable by</p>
<pre><code>os.environ[key] = val
</code></pre>
<p>which may disappear after the process exits.</p>
<p>My question is: since some of them may fail, I want to reproduce them locally, so I need the environment variables for the correct if-else path.</p>
<p>Is there a way in python to get env vars from subprocess?</p>
</div>
<div>
<div>
<p>
 asked 
</p>
</div>
<div>
<a href="https://stackoverflow.com/users/8501483/tinyden"><p></p></a>
</div>
</div>
</div>
<p></p>
</div>
<div>
<div>
<div>
<blockquote>
<p>which may disappear after the process exits</p>
</blockquote>
<p>That should be "which <strong>will</strong> disappear". In the UNIX process model env vars are private to each process. If you're on Linux you might be tempted to try reading <em>/proc/$pid/environ</em>. That however would be incorrect since it only lists the vars that were present when the process was created. It will not include any changes the process made to its own env vars.</p>
<p>In short there is no way to do what you want without the explicit cooperation of the child process.</p>
</div>
<div>
<div>
<p>
 answered 
</p>
</div>
<div>
<a href="https://stackoverflow.com/users/4276647/kurtis-rader"><p></p></a>
</div>
</div>
</div>
<h2>
</h2>
</div>
</div></div>||||I|||| Join Stack Overflow

 By clicking “Sign up”, you agree to our terms of service and acknowledge you have read our privacy policy.

 Sign up with Google
 Sign up with GitHub

 OR

 Email
 Password
 Sign up

 Already have an account? Log in
Skip to main content
 Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. Labs The future of collective knowledge sharing
 6. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. 
 1. Home
 2. Questions
 3. Tags
 4. 
 5. Users
 6. Companies
 7. Labs
 8. Discussions
 9. Collectives

 10. Communities for your favorite technologies. Explore all Collectives

 2. Teams

 Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

 Explore Teams Create a free Team
 3. Teams

 4. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 Get early access and see previews of new features.

 Learn more about Labs

 How to get environment variable in python subprocess

 Ask Question
 Asked 2 years, 6 months ago
 Modified 2 years, 6 months ago
 Viewed 203 times
 This question shows research effort; it is useful and clear
 1
 Save this question.
 Show activity on this post.

 I have a driver program which launches and manages hundreds of processes by

 p = subprocess.Popen(cmd)
 

 One of the situation I'm facing with is: since many processes may set-up their own environment variable by

 os.environ[key] = val
 

 which may disappear after the process exits.

 My question is: since some of them may fail, I want to reproduce them locally, so I need the environment variables for the correct if-else path.

 Is there a way in python to get env vars from subprocess?

 * python
 * environment-variables
 Share
 Share a link to this question
 Copy linkCC BY-SA 4.0
 Improve this question
 Follow
 Follow this question to receive notifications
 asked Oct 21, 2021 at 3:53
 Tinyden Tinyden
 554 4 4 silver badges 21 21 bronze badges
 2
 * No. If you have a way to identify each process, you can have the subprocess dump its environment to a file.
 – Tim Roberts
 Oct 21, 2021 at 3:58
 * Environment variables are process-local. They're gone when the program that sets them and its children have exited. That's always true, by-design.
 – Charles Duffy
 Oct 21, 2021 at 17:02
 Add a comment |

 1 Answer

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 This answer is useful
 1
 Save this answer.
 Show activity on this post.

 which may disappear after the process exits

 That should be "which will disappear". In the UNIX process model env vars are private to each process. If you're on Linux you might be tempted to try reading /proc/$pid/environ. That however would be incorrect since it only lists the vars that were present when the process was created. It will not include any changes the process made to its own env vars.

 In short there is no way to do what you want without the explicit cooperation of the child process.

 Share
 Share a link to this answer
 Copy linkCC BY-SA 4.0
 Improve this answer
 Follow
 Follow this answer to receive notifications
 answered Oct 21, 2021 at 17:01
 Kurtis Rader Kurtis Rader
 1
 Add a comment |

 Your Answer

 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 

 Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

 Not the answer you're looking for? Browse other questions tagged
 * python
 * environment-variables
 or ask your own question.

 * The Overflow Blog
 * Supporting the world’s most-used database engine through 2050
 * Net neutrality is in; TikTok and noncompetes are out
 * Featured on Meta
 * Testing a new version of Stack Overflow Jobs
 * Pausing the 1-rep voting experiment on Stack Overflow: reflecting on the...
 * Temporary policy: Generative AI (e.g., ChatGPT) is banned

 Related

 27
 How to get environment from a subprocess?
 0
 Environment Variable for Process
 4
 How to get the environment variables of a subprocess after it finishes running?
 1
 Python and environment variables
 2
 How to access Bash environment variable in Python using subprocess?
 7
 python: getting actual environment variables to modify and pass to subprocess
 3
 Unable to fetch the environment variables exported through subprocess
 2
 How to get environment variables after running a subprocess
 1
 Python subprocess export environment variables (which use other environment variable)
 0
 Python get env from finished subprocess

 Hot Network Questions

 * Why is sampling frequency/rate typically abbreviated Fs and not Sf in English?
 * Passionate about research in general but open to many fields: is academia for me?
 * What is it called when the root is omitted from a chord?
 * Having a second bite of the data-apple without p-hacking
 * Do multi-acceptance/multi-language automata exist in literature?
 * Should I have social media profile? Is it truly useful to create networking?
 * Does damage taken from Warding Bond count as magical?
 * Progress on Gromov's Conjecture of the bound of total Betti numbers
 * Population size change with equally probable growth and decline
 * What's the optimal area a rectangle can have inside this parabola?
 * Ground in differential opamp situation
 * If microwave ovens run at 2.4 GHz, what is the long-term effect on living tissue of exposure to this frequency, but with a thousand times less energy?
 * King cake with shy guests
 * What is the long stem growing out of my rose?
 * Should I be worried about unusual SSH login attempts from unknown IP addresses?
 * Pattern Matching on Request Body for Routing an HTTP Request
 * I was about to join a company, but rejected a day before cause of their observed work ethics. Now they are threatening me
 * In a nested multicols environment, how to only set the most inner one has separation ruler?
 * Why does df contain several tmpfs entries?
 * How are "strong" and "weak" typing defined?
 * What are the consequences or risks of signing a document with a future date?
 * How to obtain meat when you have no hunters in the colony?
 * Why did XML lose out to XHTML, then HTML 5, on the web?
 * Restrict User in an AD group from logging on to computers but allow them to use their windows credentials to log on to a webapp
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2024.4.30.8420

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
 Accept all cookies Necessary cookies only
 Customize settings
I have a driver program which launches and manages hundreds of processes by
 p = subprocess.Popen(cmd)
 
One of the situation I'm facing with is:
since many processes may set-up their own environment variable by
 os.environ[key] = val
 
which may disappear after the process exits.
My question is: since some of them may fail, I want to reproduce them locally, so I need the environment variables for the correct if-else path.
Is there a way in python to get env vars from subprocess?
 asked 
   
 
which may disappear after the process exits
That should be "which will disappear". In the UNIX process model env vars are private to each process. If you're on Linux you might be tempted to try reading /proc/$pid/environ. That however would be incorrect since it only lists the vars that were present when the process was created. It will not include any changes the process made to its own env vars.
In short there is no way to do what you want without the explicit cooperation of the child process.
 answered
How to get environment variable in python subprocess
https://stackoverflow.com/questions/69655671/how-to-get-environment-variable-in-python-subprocess
https://stackoverflow.com/questions/26146154/how-to-set-and-retrieve-environment-variable-in-python
How to set and retrieve environment variable in Python
2014-10-01
CatarinaCM CatarinaCM 1
<div><div>
 
<div>
 
 
<div>
 
 <div>
 
<p>I need to set a environment variables in the python, and I try the commands bellow</p>
<pre><code>import os
basepath = os.putenv('CPATH','/Users/cat/doc') 
basepath = os.getenv('CPATH','/Users/cat/doc') 
</code></pre>
<p>And when I print the varible, they are not set:
 print basepath
 None</p>
<p>What i'm doing wrong?</p>
<p>Rephrasing the question, I would like to create a base path based on a evironment variable. I'm testing this:</p>
<pre><code>os.environ["CPATH"] = "/Users/cat/doc"
print os.environ["CPATH"]
base_path=os.getenv('C_PATH')
</code></pre>
<p>And when I try to print the basepath:
 print basepath
it always return
None</p>
 </div>
 
 <div>
 
 <div>
 
 <div>
 <a href="/users/3029175/pgiecek"><p></p></a>
 </div>
 <div>
 <p><a href="/users/3029175/pgiecek">pgiecek</a></p><p>7,8083 gold badges36 silver badges47 bronze badges
 </p>
 </div>
</div>
 <div>
 <p>
 asked Oct 1, 2014 at 16:32
 </p>
 <div>
 <a href="/users/4011337/catarinacm"><p></p></a>
 </div>
 
</div>
 </div>
 
</div>
 <p>4</p>
 </div>
 <div>
 
 
<div>
 
 
<div>
 
 <div>
<p>Try this one.</p>
<pre><code>os.environ["CPATH"] = "/Users/cat/doc"
</code></pre>
<p>Python <a href="https://docs.python.org/2/library/os.html#process-parameters">documentation</a> is quite clear about it.</p>
<blockquote>
 <p>Calling putenv() directly does not change os.environ, so it’s better to modify os.environ.</p>
</blockquote>
<p>Based on the documentation, the <code>os.getenv()</code> is available on most flavors of Unix and Windows. OS X is not listed.</p>
<p>Use rather the snippet below to retrieve the value.</p>
<pre><code>value = os.environ.get('CPATH')
</code></pre>
 </div>
 <div>
 <p>
 answered Oct 1, 2014 at 16:37
 </p>
 <div>
 <a href="/users/3029175/pgiecek"><p></p></a>
 </div>
 <div>
 <p><a href="/users/3029175/pgiecek">pgiecek</a>pgiecek</p><p>7,8083 gold badges36 silver badges47 bronze badges
 </p>
 </div>
</div>
 
</div>
 <p>3</p>
 </div>
 
<div>
 
 <div>
<p>Use <a href="https://docs.python.org/2/library/os.html#os.environ"><code>os.environ</code></a>:</p>
<pre><code>os.environ['CPATH'] = '/Users/cat/doc' 
print os.environ['CPATH'] # /Users/cat/doc
print os.environ.get('CPATH') # /Users/cat/doc
</code></pre>
<p>See the above <a href="https://docs.python.org/2/library/os.html#os.environ">link</a> for more details:</p>
<blockquote>
 <p>If the platform supports the putenv() function, this mapping may be
 used to modify the environment as well as query the environment.
 putenv() will be called automatically when the mapping is modified.</p>
 
 <p>Note Calling putenv() directly does not change os.environ, so <strong>it’s
 better to modify os.environ.</strong></p>
</blockquote>
 </div>
 <div>
 <p>
 answered Oct 1, 2014 at 16:38
 </p>
 <div>
 <a href="/users/1361084/ofiris"><p></p></a>
 </div>
 <div>
 <p><a href="/users/1361084/ofiris">Ofiris</a>Ofiris</p><p>6,0275 gold badges34 silver badges57 bronze badges
 </p>
 </div>
</div>
 
</div>
 
<div>
 
 <div>
<p>It's a good practice to restore the environment variables at function completion.
You may need something like the <code>modified_environ</code> context manager describe in this <a href="https://stackoverflow.com/a/34333710/1513933">question</a> to restore the environment variables.</p>
<p>Usage example:</p>
<pre><code>with modified_environ(CPATH='/Users/cat/doc'):
 call_my_function()
</code></pre>
 </div>
 <div>
 
 <div>
 <a href="/users/-1/community"><p></p></a>
 </div>
 <div>
 <p>
 answered May 10, 2017 at 20:15
 </p>
 <div>
 <a href="/users/1513933/laurent-laporte"><p></p></a>
 </div>
 <div>
 <p><a href="/users/1513933/laurent-laporte">Laurent LAPORTE</a>Laurent LAPORTE</p><p>21.2k5 gold badges56 silver badges100 bronze badges
 </p>
 </div>
</div>
 </div>
 
</div>
 
 <h2>
 
 </h2>
 </div>
 </div>||||I|||| Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. Home
 2. 
 1. Public
 2. Questions
 3. Tags
 4. Users
 5. Companies
 6. Collectives
 7. Explore Collectives
 3. 
 1. Teams
 Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
 2. Teams
 3. Create free Team

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 How to set and retrieve environment variable in Python

 Ask Question
 Asked 8 years, 4 months ago
 Modified 5 years, 5 months ago
 Viewed 18k times
 6

 I need to set a environment variables in the python, and I try the commands bellow

 import os
 basepath = os.putenv('CPATH','/Users/cat/doc') 
 basepath = os.getenv('CPATH','/Users/cat/doc') 
 

 And when I print the varible, they are not set: print basepath None

 What i'm doing wrong?

 Rephrasing the question, I would like to create a base path based on a evironment variable. I'm testing this:

 os.environ["CPATH"] = "/Users/cat/doc"
 print os.environ["CPATH"]
 base_path=os.getenv('C_PATH')
 

 And when I try to print the basepath: print basepath it always return None

 * python
 * environment-variables
 Share
 Improve this question
 Follow
 edited Oct 1, 2014 at 17:41
 pgiecek
 7,808 3 3 gold badges 36 36 silver badges 47 47 bronze badges
 asked Oct 1, 2014 at 16:32
 CatarinaCM CatarinaCM
 1,085 3 3 gold badges 12 12 silver badges 21 21 bronze badges
 4
 * What operating system?
 – Ofiris
 Oct 1, 2014 at 16:46
 * OS X Mavericks (version 10.9)
 – CatarinaCM
 Oct 1, 2014 at 16:56
 * Are you using Flask ?
 – Ofiris
 Oct 1, 2014 at 17:06
 * @Ofiris: I'm having this problem and I am using Flask. os.getenv('PATH') == os.environ('PATH') == os.environ.get('PATH') == None . Got advice?
 – brandones
 Dec 12, 2014 at 2:28
 Add a comment |

 3 Answers

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 12

 Try this one.

 os.environ["CPATH"] = "/Users/cat/doc"
 

 Python documentation is quite clear about it.

 Calling putenv() directly does not change os.environ, so it’s better to modify os.environ.

 Based on the documentation, the os.getenv() is available on most flavors of Unix and Windows. OS X is not listed.

 Use rather the snippet below to retrieve the value.

 value = os.environ.get('CPATH')
 
 Share
 Improve this answer
 Follow
 edited Oct 1, 2014 at 17:04
 answered Oct 1, 2014 at 16:37
 pgiecek pgiecek
 7,808 3 3 gold badges 36 36 silver badges 47 47 bronze badges
 3
 * In this way I can print the env variable but when I try to ascribe it to a base path, eg: base_path = os.getenv('CPATH')
 – CatarinaCM
 Oct 1, 2014 at 16:42
 * @CatarinaCM, pardon? Modifying os.environ quite certainly does update the environment variables active for your script -- and base_path = os.environ.get('CPATH') [if you want None in the not-found case] is the best-practices approach to retrieval. If you're seeing contrary results, please provide a reproducer so we know how you're testing.
 – Charles Duffy
 Oct 1, 2014 at 16:44
 * Use os.environ.get('CPATH') as @Charles suggested.
 – pgiecek
 Oct 1, 2014 at 16:52
 Add a comment |
 2

 Use os.environ:

 os.environ['CPATH'] = '/Users/cat/doc' 
 print os.environ['CPATH'] # /Users/cat/doc
 print os.environ.get('CPATH') # /Users/cat/doc
 

 See the above link for more details:

 If the platform supports the putenv() function, this mapping may be used to modify the environment as well as query the environment. putenv() will be called automatically when the mapping is modified.

 Note Calling putenv() directly does not change os.environ, so it’s better to modify os.environ.

 Share
 Improve this answer
 Follow
 edited Aug 30, 2017 at 10:12
 answered Oct 1, 2014 at 16:38
 Ofiris Ofiris
 6,027 5 5 gold badges 34 34 silver badges 57 57 bronze badges
 Add a comment |
 0

 It's a good practice to restore the environment variables at function completion. You may need something like the modified_environ context manager describe in this question to restore the environment variables.

 Usage example:

 with modified_environ(CPATH='/Users/cat/doc'):
 call_my_function()
 
 Share
 Improve this answer
 Follow
 edited May 23, 2017 at 12:10
 Community Bot
 1 1 1 silver badge
 answered May 10, 2017 at 20:15
 Laurent LAPORTE Laurent LAPORTE
 21.2k 5 5 gold badges 56 56 silver badges 100 100 bronze badges
 Add a comment |

 Your Answer

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

 Not the answer you're looking for? Browse other questions tagged
 * python
 * environment-variables
 or ask your own question.

 * The Overflow Blog
 * Why developer experience is the key to better software, straight from the...
 * The frontier of computing: Q&A with IBM quantum computing research
 * Featured on Meta
 * Accessibility Update: Colors
 * 2022: a year in moderation
 * Should we burninate the [balance] tag?
 * Collectives: The next iteration
 * Temporary policy: ChatGPT is banned

 Linked

 52
 Temporarily modify the current process's environment

 Related

 2463
 Class (static) variables and methods
 3095
 How do I make function decorators and chain them together?
 3195
 How do I pass a variable by reference?
 3244
 How do I concatenate two lists in Python?
 2630
 How to upgrade all Python packages with pip?
 2988
 How can I access environment variables in Python?
 1059
 How to set environment variables in Python?
 2180
 How do I delete an exported environment variable?
 3154
 How can I delete a file or folder in Python?
 2729
 How can I remove a key from a Python dictionary?

 Hot Network Questions

 * Books containing new results
 * The word "decant" for clone generation
 * GFCI Light Is On, Test Button Doesn't Work
 * Why does Ontario have a quota on milk production?
 * Is an exhaust pipe broken at engine connection fixable by a DIYer?
 * Compute "negative" version of vector of vectors
 * What exactly is the "clutch" doing on a Shimano M8100 rear derailleur?
 * Better midi playback on mac
 * Agile Principles: What does it mean sustainable development?
 * What would be the next logical step after crossbows?
 * Find the perimeter (seemingly unsolvable problem)
 * Can "né" or "née" be used to refer to a religious's secular name?
 * Photoshop - Text to stone engraving effect
 * Crashing the sha1() function in PHP?
 * Stable words in the Proto-Indo-European language family
 * We don't own the land so is our house nearly worthless?
 * Piecewise initialisation of std::array
 * Why is witness data downloaded during IBD in prune mode?
 * I forgot to include $10 in interest in my tax return. My tax liability did not change. Should I file an amended return?
 * A functional equation
 * Why are none of these chips identifiable?
 * Did JK Rowling ever describe Harry Potter goblins as "hook-nosed"?
 * Will a spark gap transmit a signal an FM receiver can "hear?"
 * How to find the safest place to cross a frozen river from a map?
 more hot questions
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.2.6.43221

 Your privacy

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

 Accept all cookies Customize settings
I need to set a environment variables in the python, and I try the commands bellow
 import os
basepath = os.putenv('CPATH','/Users/cat/doc') 
basepath = os.getenv('CPATH','/Users/cat/doc') 
 
And when I print the varible, they are not set:
 print basepath
 None
What i'm doing wrong?
Rephrasing the question, I would like to create a base path based on a evironment variable. I'm testing this:
 os.environ["CPATH"] = "/Users/cat/doc"
print os.environ["CPATH"]
base_path=os.getenv('C_PATH')
 
And when I try to print the basepath:
 print basepath
it always return
None
 
 
 
 
 
 
 
    
 
 
  pgiecek  7,8083 gold badges36 silver badges47 bronze badges
 
 
 
 
 asked Oct 1, 2014 at 16:32
 
 
    
 
 
 
 
 4
 
 
 
 
 
 
 
 
Try this one.
 os.environ["CPATH"] = "/Users/cat/doc"
 
Python documentation is quite clear about it.
 Calling putenv() directly does not change os.environ, so it’s better to modify os.environ.
Based on the documentation, the os.getenv() is available on most flavors of Unix and Windows. OS X is not listed.
Use rather the snippet below to retrieve the value.
 value = os.environ.get('CPATH')
 
 
 
 
 answered Oct 1, 2014 at 16:37
 
 
    
 
 
  pgiecekpgiecek 7,8083 gold badges36 silver badges47 bronze badges
 
 
 
 3
 
 
 
 
Use  os.environ :
 os.environ['CPATH'] = '/Users/cat/doc' 
print os.environ['CPATH'] # /Users/cat/doc
print os.environ.get('CPATH') # /Users/cat/doc
 
See the above link for more details:
 If the platform supports the putenv() function, this mapping may be
 used to modify the environment as well as query the environment.
 putenv() will be called automatically when the mapping is modified.
 
 Note Calling putenv() directly does not change os.environ, so it’s
 better to modify os.environ. 
 
 
 
 answered Oct 1, 2014 at 16:38
 
 
    
 
 
  OfirisOfiris 6,0275 gold badges34 silver badges57 bronze badges
 
 
 
 
 
 
It's a good practice to restore the environment variables at function completion.
You may need something like the modified_environ context manager describe in this question to restore the environment variables.
Usage example:
 with modified_environ(CPATH='/Users/cat/doc'):
 call_my_function()
 
 
 
 
 
    
 
 
 
 answered May 10, 2017 at 20:15
 
 
    
 
 
  Laurent LAPORTELaurent LAPORTE 21.2k5 gold badges56 silver badges100 bronze badges
How to set and retrieve environment variable in Python
https://stackoverflow.com/questions/26146154/how-to-set-and-retrieve-environment-variable-in-python
https://stackoverflow.com/questions/62558582/unable-to-get-environment-variables-using-os-python
Unable to get environment variables using os python
2020-06-24
The Great
<div><div>
 
<p>I recently created two environment variables in my terminal as shown below</p>
<pre><code>export SPARK_HOME='/opt/spark/'
export HAIL_HOME='/home/ABCD/.pyenv/versions/3.7.2/envs/bio/lib/python3.7/site-packages/hail/'
</code></pre>
<p>When I use <code>echo $SPARK_HOME</code> or <code>echo $HAIL_HOME</code>, I am able to see the path as output</p>
<p>But, when I use the below os commands in <code>jupyter notebook</code></p>
<pre><code>os.getenv('SPARK_HOME') # able to get the output /opt/spark/
os.getenv('HAIL_HOME') # returns no output
</code></pre>
<p>I also tried defining the same variables from <code>jupyter</code> as well using <code>os.putenv</code> but even then,I see output only for <code>SPARK_HOME</code></p>
<p>However, I am able to see in my terminal screen the environment variables<code>SPARK_HOME</code> and <code>HAIL_HOME</code> using <code>printenv</code> command</p>
<p>Can help me understand what's the problem?</p>
 </div>||||I|||| Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. Home
 2. 
 1. Public
 2. Questions
 3. Tags
 4. Users
 5. Companies
 6. Collectives
 7. Explore Collectives
 3. 
 1. Teams
 Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
 2. Teams
 3. Create free Team

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 Unable to get environment variables using os python

 Ask Question
 Asked 2 years, 7 months ago
 Modified 2 years, 7 months ago
 Viewed 503 times
 1

 I recently created two environment variables in my terminal as shown below

 export SPARK_HOME='/opt/spark/'
 export HAIL_HOME='/home/ABCD/.pyenv/versions/3.7.2/envs/bio/lib/python3.7/site-packages/hail/'
 

 When I use echo $SPARK_HOME or echo $HAIL_HOME, I am able to see the path as output

 But, when I use the below os commands in jupyter notebook

 os.getenv('SPARK_HOME') # able to get the output /opt/spark/
 os.getenv('HAIL_HOME') # returns no output
 

 I also tried defining the same variables from jupyter as well using os.putenv but even then,I see output only for SPARK_HOME

 However, I am able to see in my terminal screen the environment variablesSPARK_HOME and HAIL_HOME using printenv command

 Can help me understand what's the problem?

 * python
 * apache-spark
 * environment-variables
 * python-os
 Share
 Improve this question
 Follow
 edited Jun 24, 2020 at 16:23
 The Great
 asked Jun 24, 2020 at 15:26
 The Great The Great
 6,891 7 7 gold badges 28 28 silver badges 97 97 bronze badges
 Add a comment |

 2 Answers

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 1

 I realized that it doesn't produce output for HAIL_HOME because it is installed in my virtual environment. (see .pyenv which is a hidden folder for my virtual environment`)

 However, if anyone can confirm this it's even better

 Share
 Improve this answer
 Follow
 edited Jun 24, 2020 at 16:51
 answered Jun 24, 2020 at 16:44
 The Great The Great
 6,891 7 7 gold badges 28 28 silver badges 97 97 bronze badges
 Add a comment |
 0

 use os.environ.get("SPARK_HOME").

 Share
 Improve this answer
 Follow
 answered Jun 24, 2020 at 16:20
 user3767321 user3767321
 147 2 2 silver badges 10 10 bronze badges
 2
 * Sorry, my question is on why doesn't it work for HAIL_HOME ? When I type os.environ.get("HAIL_HOME") , I get blank/no output
 – The Great
 Jun 24, 2020 at 16:21
 * *** Works for both env may be you have to see some process not overriding your exisiting environment variable.*
 – user3767321
 Jun 24, 2020 at 16:26
 Add a comment |

 Your Answer

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

 Not the answer you're looking for? Browse other questions tagged
 * python
 * apache-spark
 * environment-variables
 * python-os
 or ask your own question.

 * The Overflow Blog
 * Announcing more ways to learn and grow your skills
 * Why developer experience is the key to better software, straight from the...
 * Featured on Meta
 * Accessibility Update: Colors
 * 2022: a year in moderation
 * Collectives: The next iteration
 * We’re bringing advertisements for technology courses to Stack Overflow
 * Temporary policy: ChatGPT is banned

 Related

 2462
 Class (static) variables and methods
 7114
 What are metaclasses in Python?
 7634
 Does Python have a ternary conditional operator?
 3681
 How do I get the current time?
 3816
 Using global variables in a function
 4088
 Iterating over dictionaries using 'for' loops
 1498
 Read environment variables in Node.js
 2987
 How can I access environment variables in Python?
 1059
 How to set environment variables in Python?
 2180
 How do I delete an exported environment variable?

 Hot Network Questions

 * How to adapt a spoke salvaged from a 26" wheel to a 24" one?
 * How many spells require expensive components for each casting?
 * A standard way of marking alternate tunings for classical guitar?
 * Anydice: "highest 1 of 3d6 1d12" function. Is this correct?
 * Inconsistent interline spacing in enumitem
 * How can one order cheeses for a cheese tasting event?
 * Juvenile SF Novel With Conflict between Earth Humans and Colonists
 * Why are the trailing edges of wings not always made as 'sharp' as possible?
 * Is Metapost still relevant in the age of Lua etc.?
 * Is there a circuit that takes two single-qubit states and reflects the second around the first?
 * Crashing the sha1() function in PHP?
 * Addition and multiplication are commutative but exponentiation and tetration are not. Do we know why?
 * How do we use lowercase `\mathcal` or `\mathscr` in latex overleaf?
 * Non-inverting op-amp
 * Why Is It Important To Simulate Data From A Statistical Model?
 * How do I erase sets of solutions from Solve based on criteria?
 * How has the resolution of astronomical spectrographs improved over time?
 * EAS Build iOS Failure: Authentication with Apple Developer Portal failed
 * Stable words in the Proto-Indo-European language family
 * A very difficult functional equation
 * Sum of Consecutive Squares
 * Find the perimeter (seemingly unsolvable problem)
 * How big of an explosion can you make with a fusion reactor?
 * Idiomatic guitar notation; notating L.V. passages?
 more hot questions
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.2.3.43216

 Your privacy

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

 Accept all cookies Customize settings
I recently created two environment variables in my terminal as shown below
 export SPARK_HOME='/opt/spark/'
export HAIL_HOME='/home/ABCD/.pyenv/versions/3.7.2/envs/bio/lib/python3.7/site-packages/hail/'
 
When I use echo $SPARK_HOME or echo $HAIL_HOME, I am able to see the path as output
But, when I use the below os commands in jupyter notebook 
 os.getenv('SPARK_HOME') # able to get the output /opt/spark/
os.getenv('HAIL_HOME') # returns no output
 
I also tried defining the same variables from jupyter as well using os.putenv but even then,I see output only for SPARK_HOME 
However, I am able to see in my terminal screen the environment variablesSPARK_HOME and HAIL_HOME using printenv command
Can help me understand what's the problem?
Unable to get environment variables using os python
https://stackoverflow.com/questions/62558582/unable-to-get-environment-variables-using-os-python
https://stackoverflow.com/questions/71253807/how-to-set-windows-environment-variable-from-python
How to set windows environment variable from python
2022-02-24
Cmking Cmking
<div><div>
<p>This is how we do it in production on one of Windows servers (code is simplified):</p>
<pre><code>import winreg
regdir = "Environment-test"
keyname = "Name-test"
keyvalue = "Value-test"
def setRegistry(regdir, keyname, keyvalue):
 with winreg.CreateKey(winreg.HKEY_CURRENT_USER, regdir) as _:
 with winreg.OpenKey(winreg.HKEY_CURRENT_USER, regdir, 0, winreg.KEY_WRITE) as writeRegistryDir:
 winreg.SetValueEx(writeRegistryDir, keyname, 0, winreg.REG_SZ, keyvalue)
def getRegistry(regdir, keyname):
 with winreg.OpenKey(winreg.HKEY_CURRENT_USER, regdir) as accessRegistryDir:
 value, _ = winreg.QueryValueEx(accessRegistryDir, keyname)
 return(value)
</code></pre>
<p>If I firstly set the value using:</p>
<pre><code>setRegistry(regdir, keyname, keyvalue)
</code></pre>
<p>Then check if it's created:</p>
<p><a href="https://i.stack.imgur.com/VlDUh.png"></a></p>
<p>Now I use the getRegistry and open a PS in admin mode to run it:</p>
<pre><code>print(getRegistry(regdir, keyname))
</code></pre>
<p><a href="https://i.stack.imgur.com/wMeLB.png"></a></p>
 </div>||||I|||| Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. Home
 2. 
 1. Public
 2. Questions
 3. Tags
 4. Users
 5. Companies
 6. Collectives
 7. Explore Collectives
 3. 
 1. Teams
 Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
 2. Teams
 3. Create free Team

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 How to set windows environment variable from python

 Ask Question
 Asked 11 months ago
 Modified 11 months ago
 Viewed 1k times
 0

 I am writing a python program that needs to store a value in a persistent user environment variable. I believe these values are stored in the registry. I have tried something like this using the winreg python module.

 key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', access=winreg.KEY_WRITE) winreg.SetValueEx(key, envVarName, 0, winreg.REG_SZ, envVarValue) winreg.Close(key)

 I can see from using Registry Editor that this value is successfully set. But if I try and read the value from another python script or from a new powershell instance, I don't see the new value until the machine is rebooted.

 What else do I need to do to make this value available to other processes without rebooting?

 * python
 * windows
 * environment
 Share
 Improve this question
 Follow
 asked Feb 24, 2022 at 14:49
 cmking cmking
 41 2 2 bronze badges
 1
 * Please edit and format your code, it's really hard to read.
 – user56700
 Feb 24, 2022 at 14:55
 Add a comment |

 2 Answers

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 1

 Looking at this answer gives a possible answer: https://stackoverflow.com/a/61757725/18300067

 os.system("SETX {0} {1} /M".format("start", "test"))
 
 Share
 Improve this answer
 Follow
 answered Feb 24, 2022 at 14:59
 Ricky Chau Ricky Chau
 49 3 3 bronze badges
 1
 * Using setx in a subprocess is how we have been doing it but it is super slow. Like a second or so to set a value. I was really hoping for a better way.
 – cmking
 Feb 24, 2022 at 16:38
 Add a comment |
 0

 This is how we do it in production on one of Windows servers (code is simplified):

 import winreg
 
 regdir = "Environment-test"
 keyname = "Name-test"
 keyvalue = "Value-test"
 
 def setRegistry(regdir, keyname, keyvalue):
 with winreg.CreateKey(winreg.HKEY_CURRENT_USER, regdir) as _:
 with winreg.OpenKey(winreg.HKEY_CURRENT_USER, regdir, 0, winreg.KEY_WRITE) as writeRegistryDir:
 winreg.SetValueEx(writeRegistryDir, keyname, 0, winreg.REG_SZ, keyvalue)
 
 def getRegistry(regdir, keyname):
 with winreg.OpenKey(winreg.HKEY_CURRENT_USER, regdir) as accessRegistryDir:
 value, _ = winreg.QueryValueEx(accessRegistryDir, keyname)
 return(value)
 

 If I firstly set the value using:

 setRegistry(regdir, keyname, keyvalue)
 

 Then check if it's created:

 Now I use the getRegistry and open a PS in admin mode to run it:

 print(getRegistry(regdir, keyname))
 

 Share
 Improve this answer
 Follow
 answered Feb 24, 2022 at 15:12
 user56700 user56700
 2,176 3 3 gold badges 11 11 silver badges 20 20 bronze badges
 3
 * This sets the value in the registry. The part that I am not getting is how to get values that are set in the Environment registry to be read by new processes with out doing a reboot.
 – cmking
 Feb 24, 2022 at 16:40
 * @cmking I did not have to reboot. Worked fine the first time.
 – user56700
 Feb 24, 2022 at 17:29
 * Did it work to read them as environment variables? By using $env:keyName in a new powershell window for example. This definitely did not work for me.
 – cmking
 Feb 24, 2022 at 18:18
 Add a comment |

 Your Answer

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

 Not the answer you're looking for? Browse other questions tagged
 * python
 * windows
 * environment
 or ask your own question.

 * The Overflow Blog
 * Why developer experience is the key to better software, straight from the...
 * The frontier of computing: Q&A with IBM quantum computing research
 * Featured on Meta
 * Accessibility Update: Colors
 * 2022: a year in moderation
 * Should we burninate the [balance] tag?
 * Collectives: The next iteration
 * Temporary policy: ChatGPT is banned

 Linked

 2
 Get and Set env vars in Python on Windows

 Related

 3195
 How do I pass a variable by reference?
 3244
 How do I concatenate two lists in Python?
 2630
 How to upgrade all Python packages with pip?
 2989
 How can I access environment variables in Python?
 1059
 How to set environment variables in Python?
 2482
 How do I lowercase a string in Python?
 3154
 How can I delete a file or folder in Python?
 2729
 How can I remove a key from a Python dictionary?
 3269
 How do I select rows from a DataFrame based on column values?

 Hot Network Questions

 * A standard way of marking alternate tunings for classical guitar?
 * How to assign pointer to a rank 2 MTensor in Mathematica C code?
 * I forgot to include $10 in interest in my tax return. My tax liability did not change. Should I file an amended return?
 * Eliminate keeps the variable
 * Is 'comme platine' an idiom
 * How big of an explosion can you make with a fusion reactor?
 * What is the point of Feinting from a distance?
 * What exactly is the "clutch" doing on a Shimano M8100 rear derailleur?
 * Compute "negative" version of vector of vectors
 * Piecewise initialisation of std::array
 * Condensed Pontryagin duality
 * Not Bruce Wayne! Carry On!
 * Why is b.pop(0) over 200 times slower than del b[0] for bytearray?
 * Both "fēmina" and "mulier" mean "woman": what's the difference?
 * Computers lose power, lights dim. I suspect the mains power supply; is there anything I can do?
 * How to download only certain columns of a binary file using wget?
 * Slings for giant
 * Why is the solstice the first day of summer, and not the central day?
 * At what point does combining integrated circuits yield something patentable?
 * Calculating XOR from 1 to n: Why does this method work?
 * If a balloon lies within gun range, why would a 21st century warplane shoot it with a missile, instead of rotary guns?
 * Historic timezone offsets in newer JDK versions
 * Why are there 23 members of the grand jury?
 * Crashing the sha1() function in PHP?
 more hot questions
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.2.6.43221

 Your privacy

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

 Accept all cookies Customize settings
This is how we do it in production on one of Windows servers (code is simplified):
 import winreg
regdir = "Environment-test"
keyname = "Name-test"
keyvalue = "Value-test"
def setRegistry(regdir, keyname, keyvalue):
 with winreg.CreateKey(winreg.HKEY_CURRENT_USER, regdir) as _:
 with winreg.OpenKey(winreg.HKEY_CURRENT_USER, regdir, 0, winreg.KEY_WRITE) as writeRegistryDir:
 winreg.SetValueEx(writeRegistryDir, keyname, 0, winreg.REG_SZ, keyvalue)
def getRegistry(regdir, keyname):
 with winreg.OpenKey(winreg.HKEY_CURRENT_USER, regdir) as accessRegistryDir:
 value, _ = winreg.QueryValueEx(accessRegistryDir, keyname)
 return(value)
 
If I firstly set the value using:
 setRegistry(regdir, keyname, keyvalue)
 
Then check if it's created:
   
Now I use the getRegistry and open a PS in admin mode to run it:
 print(getRegistry(regdir, keyname))
How to set windows environment variable from python
https://stackoverflow.com/questions/71253807/how-to-set-windows-environment-variable-from-python
https://stackoverflow.com/questions/71880095/python-script-doesn-t-pick-up-environment-variable-that-is-set-in-crontab
python script doesn’t pick up environment variable that is set in crontab
2022-04-15
Andy Andy
<div><div>
 
<div>
 
 
<div>
 
 <p>When i run my python script from terminal i get error due to missing env variable. i can fix by this using <code>export</code> and setting it. But there are other python scripts that are running fine as cron jobs that require this as well. And i see this env variable being set in cron tab. So my question is if env variable set in cron is available for scripts run by user/root from cli? Running <code>env</code> command as root doesn’t show this variable.</p>
 
 <div>
 <p>
 asked Apr 15, 2022 at 4:29
 </p>
 <div>
 <a href="/users/17324608/andy"><p></p></a>
 </div>
 
</div>
 
</div>
 <p>1</p>
 </div>
 <div>
 
 
<div>
 
 
<div>
 
 <div>
<p>Environment variables are private to each process, not global. When a new process is started it inherits its initial environment from its parent. Your terminal shell isn't started by cron so it doesn't inherit the env vars you've set in your crontab.</p>
<p>Your OS may provide a standard mechanism for setting env vars for all processes (e.g., your terminal which then starts your CLI shell). What I prefer to do is create a file named <em>~/.environ</em> that I then <code>source</code> in my <em>~/.bashrc</em> and cron jobs.</p>
 </div>
 <div>
 <p>
 answered Apr 15, 2022 at 21:19
 </p>
 <div>
 <a href="/users/4276647/kurtis-rader"><p></p></a>
 </div>
 <div>
 <p><a href="/users/4276647/kurtis-rader">Kurtis Rader</a>Kurtis Rader</p><p>6,24211 silver badges16 bronze badges
 </p>
 </div>
</div>
 
</div>
 <p>1</p>
 </div>
 
 <h2>
 
 </h2>
 </div>
 </div>||||I|||| Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. Home
 2. 
 1. Public
 2. Questions
 3. Tags
 4. Users
 5. Companies
 6. Collectives
 7. Explore Collectives
 3. 
 1. Teams
 Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
 2. Teams
 3. Create free Team

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 python script doesn’t pick up environment variable that is set in crontab

 Ask Question
 Asked 9 months ago
 Modified 9 months ago
 Viewed 704 times
 1

 When i run my python script from terminal i get error due to missing env variable. i can fix by this using export and setting it. But there are other python scripts that are running fine as cron jobs that require this as well. And i see this env variable being set in cron tab. So my question is if env variable set in cron is available for scripts run by user/root from cli? Running env command as root doesn’t show this variable.

 * python
 * shell
 * cron
 * environment-variables
 Share
 Follow
 asked Apr 15, 2022 at 4:29
 Andy Andy
 11 3 3 bronze badges
 1
 * 1
 Please show a minimal script and a minimal crontab along with the outputs when run both ways and say what OS you are running. Thank you.
 – Mark Setchell
 Apr 15, 2022 at 8:04
 Add a comment |

 1 Answer

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 0

 Environment variables are private to each process, not global. When a new process is started it inherits its initial environment from its parent. Your terminal shell isn't started by cron so it doesn't inherit the env vars you've set in your crontab.

 Your OS may provide a standard mechanism for setting env vars for all processes (e.g., your terminal which then starts your CLI shell). What I prefer to do is create a file named ~/.environ that I then source in my ~/.bashrc and cron jobs.

 Share
 Follow
 answered Apr 15, 2022 at 21:19
 Kurtis Rader Kurtis Rader
 6,242 11 11 silver badges 16 16 bronze badges
 1
 * In my case it turned out that when I switched my user from root to the other one that was being used, I was able to access the env variable. So can cron set it for one user and that user can start terminal where env variable can be accessed ?
 – Andy
 Apr 18, 2022 at 23:04
 Add a comment |

 Your Answer

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

 Not the answer you're looking for? Browse other questions tagged
 * python
 * shell
 * cron
 * environment-variables
 or ask your own question.

 * The Overflow Blog
 * Why developer experience is the key to better software, straight from the...
 * The frontier of computing: Q&A with IBM quantum computing research
 * Featured on Meta
 * Accessibility Update: Colors
 * 2022: a year in moderation
 * Should we burninate the [balance] tag?
 * Collectives: The next iteration
 * Temporary policy: ChatGPT is banned

 Related

 1632
 How do I profile a Python script?
 1309
 Why do people write #!/usr/bin/env python on the first line of a Python script?
 2261
 How to check if a variable is set in Bash
 2295
 How do I set a variable to the output of a command in Bash?
 2989
 How can I access environment variables in Python?
 1059
 How to set environment variables in Python?
 2180
 How do I delete an exported environment variable?
 990
 Set environment variables from file of key/value pairs

 Hot Network Questions

 * I need a seemingly large battery for project containing several sensors, what should I do?
 * Condensed Pontryagin duality
 * Stable words in the Proto-Indo-European language family
 * He acts as if he owns (vs owned) the place?
 * We don't own the land so is our house nearly worthless?
 * Powershell Script to write printer name
 * Why do Pokemon sometimes have dark stripes in Pokemon Go?
 * New employer's code is a timebomb of epic proportions. How to deal with this accordingly?
 * how to modify a wooden fence to keep nubian goats from extending their heads over and eating dwarf tree on other side
 * Compute "negative" version of vector of vectors
 * A standard way of marking alternate tunings for classical guitar?
 * Meaning of "nude" in Saxo Grammaticus
 * How can an Indian homemaker spouse be guaranteed a Schengen tourist visa?
 * Sum of Consecutive Squares
 * Brake Fluid Bleeding Procedure
 * Historic timezone offsets in newer JDK versions
 * Why is the solstice the first day of summer, and not the central day?
 * Can "né" or "née" be used to refer to a religious's secular name?
 * Both "fēmina" and "mulier" mean "woman": what's the difference?
 * What is the mechanical advantage of a Beast Barbarian's form?
 * Intel 80188 & 8087 clock frequency differences
 * Some files have '?' in the ending, need to find such files
 * Eliminate keeps the variable
 * Can someone choose to not use their “get out of jail free” card?
 more hot questions
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.2.6.43222

 Your privacy

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

 Accept all cookies Customize settings
When i run my python script from terminal i get error due to missing env variable. i can fix by this using export and setting it. But there are other python scripts that are running fine as cron jobs that require this as well. And i see this env variable being set in cron tab. So my question is if env variable set in cron is available for scripts run by user/root from cli? Running env command as root doesn’t show this variable.
 
 
 
 asked Apr 15, 2022 at 4:29
 
 
    
 
 
 
 1
 
 
 
 
 
 
 
 
Environment variables are private to each process, not global. When a new process is started it inherits its initial environment from its parent. Your terminal shell isn't started by cron so it doesn't inherit the env vars you've set in your crontab.
Your OS may provide a standard mechanism for setting env vars for all processes (e.g., your terminal which then starts your CLI shell). What I prefer to do is create a file named ~/.environ that I then source in my ~/.bashrc and cron jobs.
 
 
 
 answered Apr 15, 2022 at 21:19
 
 
    
 
 
  Kurtis RaderKurtis Rader 6,24211 silver badges16 bronze badges
 
 
 
 1
python script doesn’t pick up environment variable that is set in crontab
https://stackoverflow.com/questions/71880095/python-script-doesn-t-pick-up-environment-variable-that-is-set-in-crontab
https://stackoverflow.com/questions/73346468/environment-variable-not-visible-in-python-application-started-from-pm2
Environment variable not visible in Python application started from pm2
2022-08-14
Roggic Roggic
<div><div>
 
<div>
 
 
<div>
 
 <div>
 
<p>I'm using a server for the first time. It has Ubuntu 18.04.<br />
I've never worked with that OS, but after some guides I managed to get my code working, except for the environment variable.<br />
In <code>~/.bashrc</code> at the end of file I added <code>export KEY="123asd"</code>.<br />
Then I reloaded the terminal.<br />
I checked if my environment variable is loaded via <code>printenv KEY</code> and it shows the correct value.<br />
In my <code>main.py</code> there's:</p>
<pre><code>import os
import telebot
API_KEY = os.getenv("KEY")
bot = telebot.TeleBot(API_KEY)
</code></pre>
<p>When I run it with <code>pm2 start main.py --interpreter=python3</code> there's an error in logs:</p>
<pre><code>raise Exception('Bot token is not defined')
Exception: Bot token is not defined
</code></pre>
<p>If I understand correctly it means that <code>API_KEY</code> is <code>None</code> so there's a problem with the environment variable.<br />
I tried giving <code>API_KEY</code> an actual value, not an environment variable, and it worked fine.<br />
So what else do I need to do to use an environment variable properly?</p>
 </div>
 
 <div>
 
 <div>
 
 <div>
 <a href="/users/14122/charles-duffy"><p></p></a>
 </div>
 <div>
 <p><a href="/users/14122/charles-duffy">Charles Duffy</a></p><p>271k42 gold badges374 silver badges430 bronze badges
 </p>
 </div>
</div>
 <div>
 <p>
 asked Aug 13, 2022 at 17:44
 </p>
 <div>
 <a href="/users/18736081/roggic"><p></p></a>
 </div>
 
</div>
 </div>
 
</div>
 <p>5</p>
 </div>
 <div>
 
 
<div>
 
 <div>
<p>I was looking in the wrong place.<br />
If I want to use <code>pm2</code> then I need to create a <code>ecosystem.config.js</code> file and give it my variable. Like this:</p>
<pre><code>module.exports = {
 apps : [{
 name: "main.py",
 env: {
 KEY: "123asd"
 }
 }]
}
</code></pre>
<p>It works, only I'm not sure if it's correct since there are more than 1 processes of my main.py (1 online, others are erorred)</p>
 </div>
 <div>
 <p>
 answered Aug 14, 2022 at 20:00
 </p>
 <div>
 <a href="/users/18736081/roggic"><p></p></a>
 </div>
 <div>
 <p><a href="/users/18736081/roggic">Roggic</a>Roggic</p><p>261 silver badge4 bronze badges
 </p>
 </div>
</div>
 
</div>
 
 <h2>
 
 </h2>
 </div>
 </div>||||I|||| Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. Home
 2. 
 1. Public
 2. Questions
 3. Tags
 4. Users
 5. Companies
 6. Collectives
 7. Explore Collectives
 3. 
 1. Teams
 Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
 2. Teams
 3. Create free Team

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 Environment variable not visible in Python application started from pm2

 Ask Question
 Asked 5 months ago
 Modified 5 months ago
 Viewed 184 times
 1

 I'm using a server for the first time. It has Ubuntu 18.04.
 I've never worked with that OS, but after some guides I managed to get my code working, except for the environment variable.
 In ~/.bashrc at the end of file I added export KEY="123asd".
 Then I reloaded the terminal.
 I checked if my environment variable is loaded via printenv KEY and it shows the correct value.
 In my main.py there's:

 import os
 import telebot
 
 API_KEY = os.getenv("KEY")
 bot = telebot.TeleBot(API_KEY)
 

 When I run it with pm2 start main.py --interpreter=python3 there's an error in logs:

 raise Exception('Bot token is not defined')
 Exception: Bot token is not defined
 

 If I understand correctly it means that API_KEY is None so there's a problem with the environment variable.
 I tried giving API_KEY an actual value, not an environment variable, and it worked fine.
 So what else do I need to do to use an environment variable properly?

 * python
 * environment-variables
 * pm2
 Share
 Improve this question
 Follow
 edited Aug 14, 2022 at 16:17
 Charles Duffy
 271k 42 42 gold badges 374 374 silver badges 430 430 bronze badges
 asked Aug 13, 2022 at 17:44
 Roggic Roggic
 26 1 1 silver badge 4 4 bronze badges
 5
 * Perhaps Python is not execute on bash session
 – Prayson W. Daniel
 Aug 13, 2022 at 18:01
 * 1
 Environment variables (aka "env vars") are not global. They are private to each process. When a process, like your shell, starts a new (child) process it hands that process a set of env vars that may, or may not, be a simple copy of its env vars. What is the pm2 command in your example? I'm guessing it's pm2.io ; specifically, pm2.io/blog/2018/09/19/Manage-Python-Processes . That document implies that pm2 has to be configured to pass the desired env vars to your Python program -- it doesn't simply inherit those of the current shell.
 – Kurtis Rader
 Aug 14, 2022 at 2:39
 * 1
 If my guess about the pm2 command in my previous comment is correct then your problem has nothing to do with Python or Ubuntu Linux. The problem is your understanding of how the PM2 application works.
 – Kurtis Rader
 Aug 14, 2022 at 2:40
 * Answers should be added with the "Add an Answer" button, not as edits to the question. That's true even if you're not sure if the answer is the best possible one: a separate answer can be upvoted, downvoted and commented on separate from the question itself.
 – Charles Duffy
 Aug 14, 2022 at 16:13
 * I’ve never had much luck with environment variables in .bashrc . I use the dotenv package and have my vars in a .env in the project root directory. pypi.org/project/python-dotenv
 – Joe Carboni
 Aug 14, 2022 at 17:25
 Add a comment |

 1 Answer

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 0

 I was looking in the wrong place.
 If I want to use pm2 then I need to create a ecosystem.config.js file and give it my variable. Like this:

 module.exports = {
 apps : [{
 name: "main.py",
 env: {
 KEY: "123asd"
 }
 }]
 }
 

 It works, only I'm not sure if it's correct since there are more than 1 processes of my main.py (1 online, others are erorred)

 Share
 Improve this answer
 Follow
 answered Aug 14, 2022 at 20:00
 Roggic Roggic
 26 1 1 silver badge 4 4 bronze badges
 Add a comment |

 Your Answer

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

 Not the answer you're looking for? Browse other questions tagged
 * python
 * environment-variables
 * pm2
 or ask your own question.

 * The Overflow Blog
 * Announcing more ways to learn and grow your skills
 * Why developer experience is the key to better software, straight from the...
 * Featured on Meta
 * Accessibility Update: Colors
 * 2022: a year in moderation
 * Collectives: The next iteration
 * We’re bringing advertisements for technology courses to Stack Overflow
 * Temporary policy: ChatGPT is banned

 Related

 1745
 Extracting extension from filename in Python
 1566
 How do I get the filename without the extension from a path in Python?
 2987
 How can I access environment variables in Python?
 1121
 List all environment variables from the command line
 1059
 How to set environment variables in Python?
 2180
 How do I delete an exported environment variable?
 2132
 Why is reading lines from stdin much slower in C++ than Python?
 685
 Adding a directory to the PATH environment variable in Windows
 2729
 How can I remove a key from a Python dictionary?
 990
 Set environment variables from file of key/value pairs

 Hot Network Questions

 * Why Is It Important To Simulate Data From A Statistical Model?
 * How do we use lowercase `\mathcal` or `\mathscr` in latex overleaf?
 * Why did Harry and the others think they could rescue Sirius?
 * Books containing new results
 * If a balloon lies within gun range, why would a 21st century warplane shoot it with a missile, instead of rotary guns?
 * adjust horizontal spacing in array environment
 * Table of unequal sequence
 * The word "decant" for clone generation
 * Anydice: "highest 1 of 3d6 1d12" function. Is this correct?
 * I forgot to include $10 in interest in my tax return. My tax liability did not change. Should I file an amended return?
 * What changes to Voyager could have been made?
 * Can a vampire rest in a coffin in a bag of holding?
 * Which Deep Learning Method to use for the classification of precious stones (diamonds, sapphire, ruby etc) based on digital photo images and data set?
 * P-channel MOSFET is always on (LTspice)
 * How to clean bath spa nozzles?
 * A standard way of marking alternate tunings for classical guitar?
 * Grant number and acknowledgment
 * At what point does combining integrated circuits yield something patentable?
 * How would you say "mindless fun" in German
 * How can an Indian homemaker spouse be guaranteed a Schengen tourist visa?
 * Is there a canonical name for a polynomial-like expression allowing for negative powers?
 * Can a helicopter's main rotor mince a human?
 * Two questions about the 4th verse of "The Star-Spangled Banner"
 * How do I erase sets of solutions from Solve based on criteria?
 more hot questions
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.2.3.43216

 Your privacy

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

 Accept all cookies Customize settings
I'm using a server for the first time. It has Ubuntu 18.04.
I've never worked with that OS, but after some guides I managed to get my code working, except for the environment variable.
In ~/.bashrc at the end of file I added export KEY="123asd".
Then I reloaded the terminal.
I checked if my environment variable is loaded via printenv KEY and it shows the correct value.
In my main.py there's:
 import os
import telebot
API_KEY = os.getenv("KEY")
bot = telebot.TeleBot(API_KEY)
 
When I run it with pm2 start main.py --interpreter=python3 there's an error in logs:
 raise Exception('Bot token is not defined')
Exception: Bot token is not defined
 
If I understand correctly it means that API_KEY is None so there's a problem with the environment variable.
I tried giving API_KEY an actual value, not an environment variable, and it worked fine.
So what else do I need to do to use an environment variable properly?
 
 
 
 
 
 
 
    
 
 
  Charles Duffy  271k42 gold badges374 silver badges430 bronze badges
 
 
 
 
 asked Aug 13, 2022 at 17:44
 
 
    
 
 
 
 
 5
 
 
 
 
 
 
I was looking in the wrong place.
If I want to use pm2 then I need to create a ecosystem.config.js file and give it my variable. Like this:
 module.exports = {
 apps : [{
 name: "main.py",
 env: {
 KEY: "123asd"
 }
 }]
}
 
It works, only I'm not sure if it's correct since there are more than 1 processes of my main.py (1 online, others are erorred)
 
 
 
 answered Aug 14, 2022 at 20:00
 
 
    
 
 
  RoggicRoggic 261 silver badge4 bronze badges
Environment variable not visible in Python application started from pm2
https://stackoverflow.com/questions/73346468/environment-variable-not-visible-in-python-application-started-from-pm2
https://stackoverflow.com/questions/62963779/sublime-text-cant-get-environment-variables-in-python
Sublime text can't get environment variables in python
2020-07-18
Heisenberg
<div><div>
 
<p>I'm was trying to run the following python code in sublime text</p>
<pre><code>import os
os.environ.get("hello")
</code></pre>
<p>I've set the value of "hello" in my environment variables to <code>hello world</code> through the following code in <code>~/.bashrc</code> file.</p>
<p><code>export hello="hello world"</code></p>
<p>When I run this code in sublime it outputs <code>None</code> while when I run the same code through terminal using the command <code>python3 main.py</code> it outputs the correct value which is <code>hello world</code>.</p>
<p>Also, when I open sublime through terminal and run the command <code>subl</code>, and when I again run the code in sublime it outputs the correct value.</p>
<p>Is there a way, I can get the correct value of the environment variables without opening sublime through terminal?</p>
<p>Note: I'm running Ubuntu 20.04</p>
<p>Edit: I've figured out the error. There wasn't a problem in script or sublime but instead I've set the environment variables in a wrong way. The environment variables set up in <code>~/.bashrc</code> are only limited to the shell. Outside of the shell, they won't work. You I needed to set system-wide variables which can be set up by changing the file <code>/etc/environment</code> and adding variables to it in the form of <code>foo="bar"</code>.</p>
 </div>||||I|||| Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. Home
 2. 
 1. Public
 2. Questions
 3. Tags
 4. Users
 5. Companies
 6. Collectives
 7. Explore Collectives
 3. 
 1. Teams
 Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
 2. Teams
 3. Create free Team

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 Sublime text can't get environment variables in python

 Ask Question
 Asked 2 years, 6 months ago
 Modified 2 years, 6 months ago
 Viewed 461 times
 1

 I'm was trying to run the following python code in sublime text

 import os
 os.environ.get("hello")
 

 I've set the value of "hello" in my environment variables to hello world through the following code in ~/.bashrc file.

 export hello="hello world"

 When I run this code in sublime it outputs None while when I run the same code through terminal using the command python3 main.py it outputs the correct value which is hello world.

 Also, when I open sublime through terminal and run the command subl, and when I again run the code in sublime it outputs the correct value.

 Is there a way, I can get the correct value of the environment variables without opening sublime through terminal?

 Note: I'm running Ubuntu 20.04

 Edit: I've figured out the error. There wasn't a problem in script or sublime but instead I've set the environment variables in a wrong way. The environment variables set up in ~/.bashrc are only limited to the shell. Outside of the shell, they won't work. You I needed to set system-wide variables which can be set up by changing the file /etc/environment and adding variables to it in the form of foo="bar".

 * python
 * environment-variables
 * sublimetext3
 Share
 Follow
 edited Jul 18, 2020 at 12:25
 Heisenberg
 asked Jul 18, 2020 at 1:45
 Heisenberg Heisenberg
 503 8 8 silver badges 22 22 bronze badges
 2
 * your code is correct, but unless you add it in your bashrc file, any new terminal you open won't have the env variable. So, for every new terminal you open you have to export hello=world
 – bigbounty
 Jul 18, 2020 at 1:49
 * I did mention that, I've added the the env variable and was able to get the value by running the code by the terminal
 – Heisenberg
 Jul 18, 2020 at 1:50
 Add a comment |

 1 Answer

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 0

 Try adding a Python build system to sublime:

 Go to Tools / Build System / New Build System and add:

 {
 'cmd': ['/usr/bin/python3', '-u', '$file'],
 'file_regex': '^[ ]*File "(…*?)", line ([0-9]*)',
 'selector': 'source.python'
 }
 

 Save the file and then select it in: Tools / Build System

 Share
 Follow
 edited Jul 18, 2020 at 4:43
 answered Jul 18, 2020 at 4:26
 Mateo Lara Mateo Lara
 807 2 2 gold badges 11 11 silver badges 27 27 bronze badges
 1
 * I've already set up my sublime build system with the exact same code.
 – Heisenberg
 Jul 18, 2020 at 12:17
 Add a comment |

 Your Answer

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

 Not the answer you're looking for? Browse other questions tagged
 * python
 * environment-variables
 * sublimetext3
 or ask your own question.

 * The Overflow Blog
 * The nature of simulating nature: Q&A with IBM quantum computing research
 * The AI that writes music from text (Ep. 535)
 * Featured on Meta
 * Accessibility Update: Colors
 * 2022: a year in moderation
 * Should we burninate the [balance] tag?
 * Collectives: The next iteration
 * Temporary policy: ChatGPT is banned

 Related

 2463
 Class (static) variables and methods
 2592
 How do I get a substring of a string in Python?
 2225
 How do I get the number of elements in a list (length of a list) in Python?
 1499
 Read environment variables in Node.js
 2989
 How can I access environment variables in Python?
 1121
 List all environment variables from the command line
 1059
 How to set environment variables in Python?
 544
 Set environment variables on Mac OS X Lion
 990
 Set environment variables from file of key/value pairs
 1209
 How do I pass environment variables to Docker containers?

 Hot Network Questions

 * Why is b.pop(0) over 200 times slower than del b[0] for bytearray?
 * Are there other countries besides Türkiye that insist their name be written in English using diacritics (or even other letters) not common in English?
 * Why is the solstice the first day of summer, and not the central day?
 * How to construct solution based on the Schrödinger equation and split it into gates?
 * When styrofoam shrinks from pressure, why doesn't it go back to normal after decreasing the pressure?
 * We don't own the land so is our house nearly worthless?
 * Compute "negative" version of vector of vectors
 * Can a helicopter's main rotor mince a human?
 * What is the up to date wording of the question about "Do you have a physical or mental disorder" on the US ESTA form?
 * Exactly two neighbors
 * How can I download only certain columns of a binary file using wget?
 * Why does faster cooling produce smaller grains?
 * First Age "of the Sun" terminology
 * A journal editor has pretended my referee report actually came from two separate referees
 * DisplayPort downstream limited to 1920×1080
 * How to play a measure with no chord notation above it?
 * What is the mechanical advantage of a Beast Barbarian's form?
 * A Murder Mystery
 * Sum numbers which are strings
 * At what point does combining integrated circuits yield something patentable?
 * Agile Principles: What does it mean sustainable development?
 * Expenditure min problem
 * Ubuntu 20.04.5 LTS package upgrade broke Docker; how recover from this?
 * I forgot to include $10 in interest in my tax return. My tax liability did not change. Should I file an amended return?
 more hot questions
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.2.6.43222

 Your privacy

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

 Accept all cookies Customize settings
I'm was trying to run the following python code in sublime text
 import os
os.environ.get("hello")
 
I've set the value of "hello" in my environment variables to hello world through the following code in ~/.bashrc file.
 export hello="hello world" 
When I run this code in sublime it outputs None while when I run the same code through terminal using the command python3 main.py it outputs the correct value which is hello world.
Also, when I open sublime through terminal and run the command subl, and when I again run the code in sublime it outputs the correct value.
Is there a way, I can get the correct value of the environment variables without opening sublime through terminal?
Note: I'm running Ubuntu 20.04
Edit: I've figured out the error. There wasn't a problem in script or sublime but instead I've set the environment variables in a wrong way. The environment variables set up in ~/.bashrc are only limited to the shell. Outside of the shell, they won't work. You I needed to set system-wide variables which can be set up by changing the file /etc/environment and adding variables to it in the form of foo="bar".
Sublime text can't get environment variables in python
https://stackoverflow.com/questions/62963779/sublime-text-cant-get-environment-variables-in-python
https://stackoverflow.com/questions/66687881/python-invisible-environment-variable-username-without-root
Python invisible environment variable USERNAME without root
2021-03-18
SUTerliakov SUTerliakov 3
<div><div>
 
<p>I wanted to use environmental variables to store some credentials and some other information for security and convenience purposes. I've put some into /etc/environment, source'd it and checked that both variables are visible both to root and normal user:</p>
<pre><code>$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
MAIL_PASSWORD="pwd"
USERNAME="un"
$ source /etc/environment
$ echo $USERNAME ";" $MAIL_PASSWORD
un ; pwd
$ sudo echo $USERNAME ";" $MAIL_PASSWORD
un ; pwd
</code></pre>
<p>Then I started python shell (it was also shown that this behavior persist when I use script and invoke it like <code>python3 test.py</code>) and tried to get this variables:</p>
<pre><code>$ python3
Python 3.8.6 (default, Jan 27 2021, 15:42:20) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import os
&gt;&gt;&gt; print(os.getenv('MAIL_PASSWORD'))
pwd
&gt;&gt;&gt; print(os.getenv('USERNAME'))
None
&gt;&gt;&gt; 
</code></pre>
<p>Well, one of them is definitely ok, but another one is hidden somehow. Trying to found out reasons of such behavior I tried the same with root privileges:</p>
<pre><code>$ sudo python3
Python 3.8.6 (default, Jan 27 2021, 15:42:20) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import os
&gt;&gt;&gt; print(os.getenv('MAIL_PASSWORD'))
pwd
&gt;&gt;&gt; print(os.getenv('USERNAME'))
un
&gt;&gt;&gt; 
</code></pre>
<p>And now everything works well.</p>
<p>I'm confused, because this problem is connected with variable name. I tried renaming USERNAME to USER and it did the trick, variable $USER is visible both for python and shell. So it's something wrong with variable name USERNAME, but I can find no information about it in docs.</p>
<p>Could anyone explain the observed results? I can just ignore it, of course, and use another variable name, but it may be interesting to find an explanation.</p>
<p>If it's related, I'm running ubuntu 20.10, this issue was found first with ubuntu 20.04. Python 3.8 version tested only.</p>
 </div>||||I|||| Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. Home
 2. 
 1. Public
 2. Questions
 3. Tags
 4. Users
 5. Companies
 6. Collectives
 7. Explore Collectives
 3. 
 1. Teams
 Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
 2. Teams
 3. Create free Team

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 Python invisible environment variable USERNAME without root

 Ask Question
 Asked 1 year, 10 months ago
 Modified 1 year, 10 months ago
 Viewed 372 times
 0

 I wanted to use environmental variables to store some credentials and some other information for security and convenience purposes. I've put some into /etc/environment, source'd it and checked that both variables are visible both to root and normal user:

 $ cat /etc/environment
 PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
 MAIL_PASSWORD="pwd"
 USERNAME="un"
 $ source /etc/environment
 $ echo $USERNAME ";" $MAIL_PASSWORD
 un ; pwd
 $ sudo echo $USERNAME ";" $MAIL_PASSWORD
 un ; pwd
 

 Then I started python shell (it was also shown that this behavior persist when I use script and invoke it like python3 test.py) and tried to get this variables:

 $ python3
 Python 3.8.6 (default, Jan 27 2021, 15:42:20) 
 [GCC 10.2.0] on linux
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> print(os.getenv('MAIL_PASSWORD'))
 pwd
 >>> print(os.getenv('USERNAME'))
 None
 >>> 
 

 Well, one of them is definitely ok, but another one is hidden somehow. Trying to found out reasons of such behavior I tried the same with root privileges:

 $ sudo python3
 Python 3.8.6 (default, Jan 27 2021, 15:42:20) 
 [GCC 10.2.0] on linux
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> print(os.getenv('MAIL_PASSWORD'))
 pwd
 >>> print(os.getenv('USERNAME'))
 un
 >>> 
 

 And now everything works well.

 I'm confused, because this problem is connected with variable name. I tried renaming USERNAME to USER and it did the trick, variable $USER is visible both for python and shell. So it's something wrong with variable name USERNAME, but I can find no information about it in docs.

 Could anyone explain the observed results? I can just ignore it, of course, and use another variable name, but it may be interesting to find an explanation.

 If it's related, I'm running ubuntu 20.10, this issue was found first with ubuntu 20.04. Python 3.8 version tested only.

 * python-3.x
 * linux
 * environment-variables
 * python-3.8
 Share
 Improve this question
 Follow
 asked Mar 18, 2021 at 9:06
 SUTerliakov SUTerliakov
 3,954 2 2 gold badges 13 13 silver badges 34 34 bronze badges
 5
 * See askubuntu.com/questions/866161/… ... especially the sections that explain the purpose of /etc/environment. I honestly dont think that such information as a username or password should go into there. Thats like the opposite of good security.
 – GhostCat
 Mar 18, 2021 at 9:11
 * $ sudo echo $USERNAME ";" $MAIL_PASSWORD is useless to show anything. Variables are expanded before running sudo anyway....
 – KamilCuk
 Mar 18, 2021 at 9:25
 * It doesn't resolve an issue. Using any other source (tried ~/.bash_profile and .env in local directory too) doesn't change the behaviour. The mentioned file was chosen because I was creating a script to be run with cron, and it was the simplest while local debugging. In final version /etc/environment is not used. I just wanna know, why does python's interpretation of envvars depend on their names or what else I don't understand.
 – SUTerliakov
 Mar 18, 2021 at 9:27
 * Augh. Yeah, you're right about expansion, thanks. Tried with sudo su , the same effect (visible both in shell and python shell).
 – SUTerliakov
 Mar 18, 2021 at 9:30
 * sudo su <user> echo $USERNAME ";" $MAIL_PASSWORD is also useless...You may want to read about how shell works and what does variable expansion and how it works, also about difference between single and double quotes - and when to use single quotes and what do they do. You may try sudo sh -c 'echo $USERNAME ";" $MAIL_PASSWORD' to have actually a sh child process that expands the variables. Or sudo -s echo '$USERNAME ; $MAIL_PASSWORD'
 – KamilCuk
 Mar 18, 2021 at 9:32
 Add a comment |

 1 Answer

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 0

 Could anyone explain the observed results?

 The results can be explained by:

 * You did not reboot/re-login/refresh PAM session.
 * The MAIL_PASSWORD variable is exported in the current shell.
 * The USERNAME variable is not exported.
 $ python3
 

 You sourced /etc/environemnt. The variable USERNAME is not exported. It will not be passed to environment of child processes. python is a child process. So it does not have the variable set. But MAIL_PASSWORD is exported in parent shell, so it is set.

 $ sudo python3
 

 sudo opens pam to run pam_env which sources and parses /etc/environemnt. The variables are exported by pam_env. The variables are thus visible in child processes.

 I wanted to use environmental variables to store some credentials and some other information for security and convenience purposes

 Great! So, opinion based:

 * If you want your variables to be visible only in PAM sessions (after you login, with a password), then put them in /etc/environment or in /etc/security/pam_env.conf. See man environment. Also this will export variables for all users on your workstation. I say you should rarely or never use /etc/environment.
 * Recommended for the whole workstation for all Bourne compatible login shells: If you want your variable to be visible in shell login sessions, set it in /etc/profile, or best add a file to /etc/profile.d if your distribution supports it. Remember to keep POSIX sh compatible syntax.
 * Similar, for csh-compatible shells there's /etc/csh.login and /etc/profile.d/*.csh.
 * If you want to set the variable for your user only login shells, use ~/.profile. For bash-only ~/.bash_profile.
 * Recommended, for single user: to set a variable for any new interactive bash shell, just use ~/.bashrc
 Share
 Improve this answer
 Follow
 edited Mar 18, 2021 at 9:45
 answered Mar 18, 2021 at 9:30
 KamilCuk KamilCuk
 111k 7 7 gold badges 50 50 silver badges 94 94 bronze badges
 3
 * Thank you. Now I've got an idea about how does it work. The first variable really was exported in ~/.bash_profile (with other value, but it doesn't matter) and it was what lead to different results. And renaming to USER reassigned the system envvar. Going to read more about shell...
 – SUTerliakov
 Mar 18, 2021 at 9:44
 * USER is set by login, see hhttps://unix.stackexchange.com/questions/76354/who-sets-user-and-username-environment-variables @edit . Pick a unique prefix, like MY_MAIL_PASSWORD and MY_USERNAME so that your variables do not interfere with other. USERNAME looks like a too simple variable name.
 – KamilCuk
 Mar 18, 2021 at 9:46
 * Yes, did it to test and finally understand, what exactly I was doing wrong. Without exporting none of them were visible when a unique name was chosen.
 – SUTerliakov
 Mar 18, 2021 at 9:51
 Add a comment |

 Your Answer

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

 Not the answer you're looking for? Browse other questions tagged
 * python-3.x
 * linux
 * environment-variables
 * python-3.8
 or ask your own question.

 * The Overflow Blog
 * Why developer experience is the key to better software, straight from the...
 * The frontier of computing: Q&A with IBM quantum computing research
 * Featured on Meta
 * Accessibility Update: Colors
 * 2022: a year in moderation
 * Should we burninate the [balance] tag?
 * Collectives: The next iteration
 * Temporary policy: ChatGPT is banned

 Related

 1181
 Defining a variable with or without export
 2989
 How can I access environment variables in Python?
 1059
 How to set environment variables in Python?
 2180
 How do I delete an exported environment variable?
 7
 os.environ doesn't show some variables
 685
 Adding a directory to the PATH environment variable in Windows
 4
 Getting Environment Variable $PATH in Linux using C++ in Eclipse
 1
 How can I manage mutiple python in Ubuntu16.04?
 9
 QGIS3 won't install on mac with python3.6 already installed through Ananconda
 106
 Make python3 as my default python on Mac

 Hot Network Questions

 * Why are there 23 members of the grand jury?
 * I forgot to include $10 in interest in my tax return. My tax liability did not change. Should I file an amended return?
 * Why does faster cooling produce smaller grains?
 * Intel 80188 & 8087 clock frequency differences
 * Why do Pokemon sometimes have dark stripes in Pokemon Go?
 * At what point does combining integrated circuits yield something patentable?
 * Smallest square that can pack thin digits
 * Psalm 7:9 and meaning of the word "reins" within the context
 * Addition and multiplication are commutative but exponentiation and tetration are not. Do we know why?
 * Is Metapost still relevant in the age of Lua etc.?
 * What do you do when you're stuck at a problem?
 * Crashing the sha1() function in PHP?
 * Reverse the polyglot, change the language
 * How are business travel expenses usually reported when using the Dutch public transport system?
 * Find the perimeter (seemingly unsolvable problem)
 * When did Kievan Rus' rulers become culturally Slavic?
 * What exactly is the "clutch" doing on a Shimano M8100 rear derailleur?
 * Books containing new results
 * Can "né" or "née" be used to refer to a religious's secular name?
 * Is possible to use a 220 V to 220 V isolation transformer for 110 V and get 110 V in the secondary?
 * Computers lose power, lights dim. I suspect the mains power supply; is there anything I can do?
 * Why is the solstice the first day of summer, and not the central day?
 * Agile Principles: What does it mean sustainable development?
 * Can a creature be targeted by future uses of eyebite if they are immune to the initial casting?
 more hot questions
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.2.6.43222

 Your privacy

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

 Accept all cookies Customize settings
I wanted to use environmental variables to store some credentials and some other information for security and convenience purposes. I've put some into /etc/environment, source'd it and checked that both variables are visible both to root and normal user:
 $ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
MAIL_PASSWORD="pwd"
USERNAME="un"
$ source /etc/environment
$ echo $USERNAME ";" $MAIL_PASSWORD
un ; pwd
$ sudo echo $USERNAME ";" $MAIL_PASSWORD
un ; pwd
 
Then I started python shell (it was also shown that this behavior persist when I use script and invoke it like python3 test.py) and tried to get this variables:
 $ python3
Python 3.8.6 (default, Jan 27 2021, 15:42:20) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import os
&gt;&gt;&gt; print(os.getenv('MAIL_PASSWORD'))
pwd
&gt;&gt;&gt; print(os.getenv('USERNAME'))
None
&gt;&gt;&gt; 
 
Well, one of them is definitely ok, but another one is hidden somehow. Trying to found out reasons of such behavior I tried the same with root privileges:
 $ sudo python3
Python 3.8.6 (default, Jan 27 2021, 15:42:20) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import os
&gt;&gt;&gt; print(os.getenv('MAIL_PASSWORD'))
pwd
&gt;&gt;&gt; print(os.getenv('USERNAME'))
un
&gt;&gt;&gt; 
 
And now everything works well.
I'm confused, because this problem is connected with variable name. I tried renaming USERNAME to USER and it did the trick, variable $USER is visible both for python and shell. So it's something wrong with variable name USERNAME, but I can find no information about it in docs.
Could anyone explain the observed results? I can just ignore it, of course, and use another variable name, but it may be interesting to find an explanation.
If it's related, I'm running ubuntu 20.10, this issue was found first with ubuntu 20.04. Python 3.8 version tested only.
Python invisible environment variable USERNAME without root
https://stackoverflow.com/questions/66687881/python-invisible-environment-variable-username-without-root
https://stackoverflow.com/questions/71803207/get-conda-environment-variable-inside-jupyter-notebook
Get conda environment variable inside Jupyter Notebook
2022-04-08
Augusto Fonseca
<div><div>
 
<div>
 
 <div>
 
<p>With my conda environment activated I set an environment variable with the command</p>
<pre><code>conda env config vars set ROOT_DIRECTORY=$PWD
</code></pre>
<p>Now, if a run <code>echo $ROOT_DIRECTORY</code> the output shows <code>/home/augusto/myproject</code></p>
<p>How can I get that variable inside Jupyter Notebook? I tried with the command below, but the output shows <code>None</code>.</p>
<pre><code>import os
print(os.getenv('ROOT_DIRECTORY'))
</code></pre>
<p>By the way, I have shure that Jupyter Notebook are using the correct Kernel. Running the above code inside a <code>.py</code> file works correctly, i.e. the output shows <code>/home/augusto/myproject</code>.</p>
 </div>
 
 <div>
 <p>
 asked Apr 8, 2022 at 21:15
 </p>
 <div>
 <a href="/users/18750395/augusto-fonseca"><p></p></a>
 </div>
 
</div>
 
</div>
 <div>
 
 
<div>
 
 <div>
<p>Find env dir</p>
<pre><code>jupyter kernelspec list
 
cd path_to_kernel_dir
sudo nano kernel.json
</code></pre>
<p>Add environment section to json</p>
<p>json should look something like this</p>
<pre><code>{
 "argv": [
 "/home/jupyter-admin/.conda/envs/tf/bin/python3",
 "-m",
 "ipykernel_launcher",
 "-f",
 "{connection_file}"
 ],
 "env": {"LD_LIBRARY_PATH":"/home/jupyter-admin/.conda/envs/tf/lib/"},
 "display_name": "tf_gpu",
 "language": "python",
 "metadata": {
 "debugger": true
 }
}
</code></pre>
 </div>
 <div>
 <p>
 answered Aug 15, 2022 at 13:26
 </p>
 <div>
 <a href="/users/7690220/alexander-volinski"><p></p></a>
 </div>
 
</div>
 
</div>
 
 <h2>
 
 </h2>
 </div>
 </div>||||I|||| Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. Home
 2. 
 1. Public
 2. Questions
 3. Tags
 4. Users
 5. Companies
 6. Collectives
 7. Explore Collectives
 3. 
 1. Teams
 Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
 2. Teams
 3. Create free Team

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 Get conda environment variable inside Jupyter Notebook

 Ask Question
 Asked 10 months ago
 Modified 6 months ago
 Viewed 572 times
 1

 With my conda environment activated I set an environment variable with the command

 conda env config vars set ROOT_DIRECTORY=$PWD
 

 Now, if a run echo $ROOT_DIRECTORY the output shows /home/augusto/myproject

 How can I get that variable inside Jupyter Notebook? I tried with the command below, but the output shows None.

 import os
 print(os.getenv('ROOT_DIRECTORY'))
 

 By the way, I have shure that Jupyter Notebook are using the correct Kernel. Running the above code inside a .py file works correctly, i.e. the output shows /home/augusto/myproject.

 * python
 * jupyter-notebook
 * environment-variables
 * conda
 Share
 Follow
 edited Apr 8, 2022 at 21:30
 Augusto Fonseca
 asked Apr 8, 2022 at 21:15
 Augusto Fonseca Augusto Fonseca
 11 3 3 bronze badges
 Add a comment |

 1 Answer

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 0

 Find env dir

 jupyter kernelspec list
 
 cd path_to_kernel_dir
 
 sudo nano kernel.json
 

 Add environment section to json

 json should look something like this

 {
 "argv": [
 "/home/jupyter-admin/.conda/envs/tf/bin/python3",
 "-m",
 "ipykernel_launcher",
 "-f",
 "{connection_file}"
 ],
 "env": {"LD_LIBRARY_PATH":"/home/jupyter-admin/.conda/envs/tf/lib/"},
 "display_name": "tf_gpu",
 "language": "python",
 "metadata": {
 "debugger": true
 }
 }
 
 Share
 Follow
 answered Aug 15, 2022 at 13:26
 Alexander Volinski Alexander Volinski
 41 5 5 bronze badges
 Add a comment |

 Your Answer

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

 Not the answer you're looking for? Browse other questions tagged
 * python
 * jupyter-notebook
 * environment-variables
 * conda
 or ask your own question.

 * The Overflow Blog
 * ML and AI consulting-as-a-service (Ep. 541)
 * Why governments need open source more than ever
 * Featured on Meta
 * Ticket smash for [status-review] tag: Part Deux
 * We've added a "Necessary cookies only" option to the cookie consent popup

 Related

 2192
 How do I delete an exported environment variable?
 72
 Link Conda environment with Jupyter Notebook
 541
 Conda environments not showing up in Jupyter Notebook
 536
 How can I rename a conda environment?
 665
 Removing Conda environment
 698
 How do I prevent Conda from activating the base environment by default?
 2
 Jupyter & Terminal have different Conda packages
 0
 Use conda environment in Jupyter Notebook

 Hot Network Questions

 * article usage, He invented THE slide rule
 * Definite integrals with equal limits
 * ddrescue: How to restart from pass 1?
 * Dilation of bounded linear operators
 * What is name of this part on a helicopter?
 * Why would/wouldn't *humanoid* robots become popular, rather than any other robotic body-form?
 * How did this ceiling exhaust fan get stuck on (and why did disconnecting this wire fix it)?
 * How to print leading zeros (padding) in awk?
 * What is the circuit symbol for a triple gang potentiometer?
 * How to create scales on an dragon egg?
 * Potential and Field
 * Which philosophers have considered irrational conviction
 * Why do heating curves have plateaus?
 * Does distant metamagic feat when applied to storm sphere apply to the 60' range of the bonus action lightning bolt?
 * What does it mean to "have had abolition of war"?
 * You don't use a comma listing only two items, but SAT Reading Passage does. Why?
 * How safe it would be to look at the other planet in double-planet system with naked eye?
 * Is the "Chinese room" an explanation of how ChatGPT works?
 * Identify these old accounting machines
 * Discrete N-channel-MOSFET driver switching circuit with NPN and PNP transistor
 * Is there a colloquial word/expression for a push that helps you to start to do something?
 * Is it safe to transport a gas water heater laying down?
 * Shortcut of finding a tangent line and tangent point to a curve that's explicitly or implicitly defined
 * Sci fi book about a character with an implant/enhanced capabilities who was hired to assassinate a member of elite society
 more hot questions
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.2.24.43259

 Your privacy

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

 Accept all cookies Necessary cookies only
 Customize settings
With my conda environment activated I set an environment variable with the command
 conda env config vars set ROOT_DIRECTORY=$PWD
 
Now, if a run echo $ROOT_DIRECTORY the output shows /home/augusto/myproject 
How can I get that variable inside Jupyter Notebook? I tried with the command below, but the output shows None.
 import os
print(os.getenv('ROOT_DIRECTORY'))
 
By the way, I have shure that Jupyter Notebook are using the correct Kernel. Running the above code inside a .py file works correctly, i.e. the output shows /home/augusto/myproject.
 
 
 
 
 asked Apr 8, 2022 at 21:15
 
 
    
 
 
 
 
 
 
 
 
Find env dir
 jupyter kernelspec list
 
cd path_to_kernel_dir
sudo nano kernel.json
 
Add environment section to json
json should look something like this
 {
 "argv": [
 "/home/jupyter-admin/.conda/envs/tf/bin/python3",
 "-m",
 "ipykernel_launcher",
 "-f",
 "{connection_file}"
 ],
 "env": {"LD_LIBRARY_PATH":"/home/jupyter-admin/.conda/envs/tf/lib/"},
 "display_name": "tf_gpu",
 "language": "python",
 "metadata": {
 "debugger": true
 }
}
 
 
 
 
 answered Aug 15, 2022 at 13:26
Get conda environment variable inside Jupyter Notebook
https://stackoverflow.com/questions/71803207/get-conda-environment-variable-inside-jupyter-notebook
https://stackoverflow.com/questions/60435406/which-exception-should-be-raised-when-a-required-environment-variable-is-missing
Which exception should be raised when a required environment variable is missing?
2020-03-11
TomMP TomMP
<div><div>
<p>By default <code>KeyError</code> is already raised when an environment variable doesn't exist. <code>os.environ["THISENVDOESNTEXIST"]</code></p>
<p>Furthermore you can supply a default variable if the env variable doesn't exist. Doing this won't raise the error. <code>os.environ.get("THISENVDOESNTEXIST", "defaultvalue")</code></p>
<p>Code executed:</p>
<pre><code>Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import os
&gt;&gt;&gt; os.environ["THISENVDOESNTEXIST"]
Traceback (most recent call last):
 File "&lt;stdin&gt;", line 1, in &lt;module&gt;
 File "C:\Users\Tin\AppData\Local\Programs\Python\Python37\lib\os.py", line 678, in __getitem__
 raise KeyError(key) from None
KeyError: 'THISENVDOESNTEXIST'
&gt;&gt;&gt; os.environ.get("THISENVDOESNTEXIST", "defaultvalue")
'defaultvalue'
</code></pre>
<p>If you want to raise your own custom error you can do this:</p>
<pre><code>class MyException(Exception):
 pass
try:
 os.environ["THISENVDOESNTEXIST"]
except KeyError as e:
 raise MyException("Tried accessing an environment variable that does not exist")
</code></pre>
 </div>||||I|||| Stack Overflow
 1. About
 2. Products
 3. For Teams
 1. Stack Overflow Public questions & answers
 2. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
 3. Talent Build your employer brand
 4. Advertising Reach developers & technologists worldwide
 5. About the company
 Loading…

 1. current community

 + Stack Overflow
 help chat
 + Meta Stack Overflow

 your communities

 Sign up or log in to customize your list.

 more stack exchange communities

 company blog
 2. 
 3. Log in
 4. Sign up
 1. Home
 2. 
 1. Public
 2. Questions
 3. Tags
 4. Users
 5. Companies
 6. Collectives
 7. Explore Collectives
 3. 
 1. Teams
 Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
 2. Teams
 3. Create free Team

 Collectives™ on Stack Overflow

 Find centralized, trusted content and collaborate around the technologies you use most.

 Learn more about Collectives

 Teams

 Q&A for work

 Connect and share knowledge within a single location that is structured and easy to search.

 Learn more about Teams

 Which exception should be raised when a required environment variable is missing?

 Ask Question
 Asked 2 years, 11 months ago
 Modified 2 months ago
 Viewed 12k times
 21

 The title pretty much sums it up already.

 I have a piece of code that calls os.getenv to get both a URL as well as a token in order to connect to a service. The code lives in a module and will only be imported from there, i.e. it's not a script.

 It's not a huge issue at all, since I really only need to crash and display the message saying that there are unset values, but it got me thinking about which of Python's built-in exceptions would be the best fit.

 I found the EnvironmentError, but that seems to function as base class from which IOError and other OS related exceptions inherit.

 Would it be as simple as a ValueError, as it's really just a value that's missing?

 Thanks!

 * python
 * python-3.x
 * exception
 Share
 Improve this question
 Follow
 edited Mar 11, 2020 at 19:15
 n8mob
 266 4 4 silver badges 9 9 bronze badges
 asked Feb 27, 2020 at 14:25
 TomMP TomMP
 685 1 1 gold badge 5 5 silver badges 15 15 bronze badges
 Add a comment |

 4 Answers

 Sorted by: Reset to default
 Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
 8

 You can make your own exceptions for specific cases by inheriting from Exception

 class MissingEnvironmentVariable(Exception):
 pass
 
 
 def get_my_env_var(var_name):
 try:
 return os.environ[var_name]
 except KeyError:
 raise MissingEnvironmentVariable(f"{var_name} does not exist")
 
 Share
 Improve this answer
 Follow
 edited Nov 30, 2022 at 12:07
 answered Feb 27, 2020 at 14:32
 Kathy Rindhoops Kathy Rindhoops
 1,078 8 8 silver badges 20 20 bronze badges
 1
 * 1
 it's missing the 'return envvar'
 – Renato Cron
 Nov 29, 2022 at 18:54
 Add a comment |
 7

 Well most built in concrete exception classes are for specific use cases, and this one does not really fit in any but RuntimeError. But I would advise you to use a custom Exception subclass.

 Share
 Improve this answer
 Follow
 answered Feb 27, 2020 at 14:32
 Serge Ballesta Serge Ballesta
 141k 11 11 gold badges 119 119 silver badges 241 241 bronze badges
 5
 * 1
 Thanks, I was actually looking to avoid creating my own exception. Batteries included and all that, I thought there surely has to be some built-in exception that fits. Oh well!
 – TomMP
 Feb 27, 2020 at 14:41
 * When you are accessing an env variable that does not exist in Python it will raise ValueError by default. See my answer.
 – Tin Nguyen
 Feb 27, 2020 at 14:43
 * 1
 I think you mean KeyError , right? In any case, I should have been more specific in my question. I'm accessing it through os.getenv , with no default value. Afterwards I'm performing the check and throw an error, if need be. Thanks anyway, I gave all of you well-deserved +1's :)
 – TomMP
 Feb 27, 2020 at 14:45
 * 1
 @TinNguyen: I assume that OP wants to filter the ValueError or access the environment in a way that does not throw it. But you are right on the KeyError point.
 – Serge Ballesta
 Feb 27, 2020 at 14:47
 * 1
 Yea KeyError my fault. The thing is you don't need to manually throw it since it is already thrown. It only makes sense to throw it if you have a custom logic for handling that error specifically. In which case it makes sense to raise your own custom error. So you can catch that error specifically. KeyError s are also raised when accessing a value from a dictionary through a key that does not exist. Those errors you might not want to catch since you might not have a way of handling those errors specifically.
 – Tin Nguyen
 Feb 27, 2020 at 14:51
 Add a comment |
 7

 You could always create a custom exception

 https://www.programiz.com/python-programming/user-defined-exception https://docs.python.org/3/tutorial/errors.html

 Ive used this guide before:

 Something simple like

 class UnconfiguredEnvironment(Exception):
 """base class for new exception"""
 pass
 
 if not os.environ.get("URL",None):
 raise UnconfiguredEnvironment
 
 

 Use the guides to extend as you see fit.

 Share
 Improve this answer
 Follow
 answered Feb 27, 2020 at 14:37
 tomgalpin tomgalpin
 1,703 4 4 silver badges 12 12 bronze badges
 2
 * Thanks! As I said in another comment I was hoping to avoid having to do that, but it does not matter much in the end. I just though surely there has to be a built-in one.
 – TomMP
 Feb 27, 2020 at 14:42
 * 1
 A great list to reference against is docs.python.org/3/library/exceptions.html
 – tomgalpin
 Feb 27, 2020 at 14:45
 Add a comment |
 6

 By default KeyError is already raised when an environment variable doesn't exist. os.environ["THISENVDOESNTEXIST"]

 Furthermore you can supply a default variable if the env variable doesn't exist. Doing this won't raise the error. os.environ.get("THISENVDOESNTEXIST", "defaultvalue")

 Code executed:

 Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> os.environ["THISENVDOESNTEXIST"]
 Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "C:\Users\Tin\AppData\Local\Programs\Python\Python37\lib\os.py", line 678, in __getitem__
 raise KeyError(key) from None
 KeyError: 'THISENVDOESNTEXIST'
 >>> os.environ.get("THISENVDOESNTEXIST", "defaultvalue")
 'defaultvalue'
 

 If you want to raise your own custom error you can do this:

 class MyException(Exception):
 pass
 
 try:
 os.environ["THISENVDOESNTEXIST"]
 except KeyError as e:
 raise MyException("Tried accessing an environment variable that does not exist")
 
 Share
 Improve this answer
 Follow
 answered Feb 27, 2020 at 14:31
 Tin Nguyen Tin Nguyen
 5,080 1 1 gold badge 10 10 silver badges 30 30 bronze badges
 Add a comment |

 Your Answer

 Thanks for contributing an answer to Stack Overflow!

 * Please be sure to answer the question. Provide details and share your research!

 But avoid …

 * Asking for help, clarification, or responding to other answers.
 * Making statements based on opinion; back them up with references or personal experience.

 To learn more, see our tips on writing great answers.

 Sign up or log in

 Sign up using Google
 Sign up using Facebook
 Sign up using Email and Password
 Submit

 Post as a guest

 Name
 Email

 Required, but never shown

 Post as a guest

 Name
 Email

 Required, but never shown

 Post Your Answer Discard

 By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

 Not the answer you're looking for? Browse other questions tagged
 * python
 * python-3.x
 * exception
 or ask your own question.

 * The Overflow Blog
 * Announcing more ways to learn and grow your skills
 * Why developer experience is the key to better software, straight from the...
 * Featured on Meta
 * Accessibility Update: Colors
 * 2022: a year in moderation
 * Collectives: The next iteration
 * We’re bringing advertisements for technology courses to Stack Overflow
 * Temporary policy: ChatGPT is banned
 Visit chat

 Related

 491
 When to throw an exception?
 774
 Which exception should I raise on bad/illegal argument combinations in Python?
 149
 .NET: Which Exception to Throw When a Required Configuration Setting is Missing?
 577
 Get exception description and stack trace which caused an exception, all as a string
 675
 When should I really use noexcept?
 408
 TypeError: Missing 1 required positional argument: 'self'
 675
 How to properly assert that an exception gets raised in pytest?
 851
 "TypeError: a bytes-like object is required, not 'str'" when handling file content in Python 3

 Hot Network Questions

 * Calculating XOR from 1 to n: Why does this method work?
 * In an underdetermined linear regression setup, why does the residual sum of squares equal 0?
 * Addition and multiplication are commutative but exponentiation and tetration are not. Do we know why?
 * Not Bruce Wayne! Carry On!
 * Should I meet my boss when I travel to his/her country?
 * How to download only certain columns of a binary file using wget?
 * Non-inverting op-amp
 * Why Is It Important To Simulate Data From A Statistical Model?
 * At what point does combining integrated circuits yield something patentable?
 * If Sauron wins eventually without the Ring, why weren't Elrond/Gandalf in panic mode before Frodo showed up?
 * How many spells require expensive components for each casting?
 * Is there a canonical name for a polynomial-like expression allowing for negative powers?
 * What changes to Voyager could have been made?
 * Why are atoms electrically neutral?
 * How has the resolution of astronomical spectrographs improved over time?
 * GFCI Light Is On, Test Button Doesn't Work
 * What did Paul McCartney mean by "Oh, yesterday came suddenly"?
 * (Rev. 2) Command-line Tower of Hanoi game
 * Both "fēmina" and "mulier" mean "woman": what's the difference?
 * How to find the safest place to cross a frozen river from a map?
 * How do I erase sets of solutions from Solve based on criteria?
 * Why does Ontario have a quota on milk production?
 * 2 tabulars with supposed same size aren't actually the same size
 * Why do Pokemon sometimes have dark stripes in Pokemon Go?
 more hot questions
 Question feed

 Subscribe to RSS

 Question feed

 To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

 Stack Overflow

 * Questions
 * Help

 Products

 * Teams
 * Advertising
 * Collectives
 * Talent

 Company

 * About
 * Press
 * Work Here
 * Legal
 * Privacy Policy
 * Terms of Service
 * Contact Us
 * Cookie Settings
 * Cookie Policy

 Stack Exchange Network

 * Technology
 * Culture & recreation
 * Life & arts
 * Science
 * Professional
 * Business
 * API
 * Data
 * Blog
 * Facebook
 * Twitter
 * LinkedIn
 * Instagram

 Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.2.6.43219

 Your privacy

 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

 Accept all cookies Customize settings
By default KeyError is already raised when an environment variable doesn't exist. os.environ["THISENVDOESNTEXIST"] 
Furthermore you can supply a default variable if the env variable doesn't exist. Doing this won't raise the error. os.environ.get("THISENVDOESNTEXIST", "defaultvalue") 
Code executed:
 Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import os
&gt;&gt;&gt; os.environ["THISENVDOESNTEXIST"]
Traceback (most recent call last):
 File "&lt;stdin&gt;", line 1, in &lt;module&gt;
 File "C:\Users\Tin\AppData\Local\Programs\Python\Python37\lib\os.py", line 678, in __getitem__
 raise KeyError(key) from None
KeyError: 'THISENVDOESNTEXIST'
&gt;&gt;&gt; os.environ.get("THISENVDOESNTEXIST", "defaultvalue")
'defaultvalue'
 
If you want to raise your own custom error you can do this:
 class MyException(Exception):
 pass
try:
 os.environ["THISENVDOESNTEXIST"]
except KeyError as e:
 raise MyException("Tried accessing an environment variable that does not exist")
Which exception should be raised when a required environment variable is missing?
https://stackoverflow.com/questions/60435406/which-exception-should-be-raised-when-a-required-environment-variable-is-missing
https://en.wikipedia.org/wiki/Environment_variable
Environment variable - Wikipedia
2003-10-25
None
<div><div>
<p>An <b>environment variable</b> is a <a href="/wiki/Name_resolution_(programming_languages)">dynamic-named</a> <a href="/wiki/Value_(computer_science)">value</a> that can affect the way running <a href="/wiki/Process_(computing)">processes</a> will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store <a href="/wiki/Temporary_file">temporary files</a>, or the HOME or USERPROFILE variable to find the <a href="/wiki/Directory_structure">directory structure</a> owned by the user running the process.
</p><p>They were introduced in their modern form in 1979 with <a href="/wiki/Version_7_Unix">Version 7 Unix</a>, so are included in all <a href="/wiki/Unix">Unix</a> <a href="/wiki/Operating_system">operating system</a> flavors and variants from that point onward including <a href="/wiki/Linux">Linux</a> and <a href="/wiki/MacOS">macOS</a>. From <a href="/wiki/PC_DOS_2.0">PC DOS 2.0</a> in 1982, all succeeding <a href="/wiki/Microsoft">Microsoft</a> operating systems, including <a href="/wiki/Microsoft_Windows">Microsoft Windows</a>, and <a href="/wiki/OS/2">OS/2</a> also have included them as a feature, although with somewhat different syntax, usage and standard variable names.
</p>
<h2>Design[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=1">edit</a>]</h2>
<p>In all <a href="/wiki/Unix">Unix</a> and <a href="/wiki/Unix-like">Unix-like</a> systems, as well as on Windows, each process has its own separate set of environment <a href="/wiki/Variable_(programming)">variables</a>. By default, when a process is created, it inherits a duplicate <a href="/wiki/Run-time_environment">run-time environment</a> of its parent process, except for explicit changes made by the parent when it creates the child. At the <a href="/wiki/Application_programming_interface">API</a> level, these changes must be done between running <code>fork</code> and <code>exec</code>. Alternatively, from <a href="/wiki/Command_shell">command shells</a> such as <a href="/wiki/Bash_(Unix_shell)">bash</a>, a user can change environment variables for a particular command invocation by indirectly invoking it via <code><a href="/wiki/Env">env</a></code> or using the <code>ENVIRONMENT_VARIABLE=VALUE &lt;command&gt;</code> notation. A running program can access the values of environment variables for configuration purposes.
</p><p><a href="/wiki/Shell_script">Shell scripts</a> and batch files use environment variables to communicate data and preferences to <a href="/wiki/Child_process">child processes</a>. They can also be used to store temporary values for reference later in a shell script. However, in Unix, <a href="#Unix">non-exported variables</a> are preferred for this as they don't leak outside the process.
</p><p>In Unix, an environment variable that is changed in a script or compiled program will only affect that process and possibly child processes. The parent process and any unrelated processes will not be affected. Similarly, changing or removing a variable's value inside a <a href="/wiki/DOS">DOS</a> or Windows batch file will change the variable for the duration of <code><a href="/wiki/COMMAND.COM">COMMAND.COM</a></code>or <code><a href="/wiki/CMD.EXE">CMD.EXE</a></code>'s existence, respectively.
</p><p>In Unix, the environment variables are normally initialized during system startup by the system <a href="/wiki/Init">init</a> <a href="/wiki/Startup_script">startup scripts</a>, and hence inherited by all other processes in the system. Users can, and often do, augment them in the profile script for the command shell they are using. In Microsoft Windows, each environment variable's default value is stored in the <a href="/wiki/Windows_Registry">Windows Registry</a> or set in the <code><a href="/wiki/AUTOEXEC.BAT">AUTOEXEC.BAT</a></code> file.
</p><p>On <a href="/wiki/Unix">Unix</a>, a <a href="/wiki/Setuid">setuid</a> program is given an environment chosen by its caller, but it runs with different authority from its caller. The <a href="/wiki/Dynamic_linker">dynamic linker</a> will usually load code from locations specified by the environment variables <code>$LD_LIBRARY_PATH</code> and <code>$LD_PRELOAD</code> 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, <a href="/wiki/Libc">libc</a> 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.
</p><p>In general, the collection of environment variables function as an <a href="/wiki/Associative_array">associative array</a> where both the keys and values are strings. The interpretation of characters in either string differs among systems. When data structures such as lists need to be represented, it is common to use a colon (common on Unix and Unix-like) or semicolon-deliminated (common on Windows and DOS) list.
</p>
<h2>Syntax[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=2">edit</a>]</h2>
<p>The variables can be used both in scripts and on the <a href="/wiki/Command_line">command line</a>. They are usually referenced by putting special symbols in front of or around the variable name.
</p><p>It is conventional for environment variable names to be chosen to be in all upper case. In programming code generally, this helps to distinguish environment variables from other kinds of names in the code. On Unix-like operating systems, environment variable names are case sensitive, but they are not on DOS, OS/2, and Windows.
</p>
<h3>Unix[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=3">edit</a>]</h3>
<p>In most Unix and Unix-like <a href="/wiki/Command-line_shell">command-line shells</a>, an environment variable's value is retrieved by placing a <code>$</code> sign before the variable's name. If necessary, the name can also be surrounded by braces.
</p><p>To display the user home directory, the user may type:
</p>
<p>If <code>xyz</code> needed to be appended to the value of the <code>HOME</code> variable, one might type:
</p>
<p>In Unix and Unix-like systems, the names of environment variables are case-sensitive.
</p><p>The command <b><code><a href="/wiki/Env_(shell)">env</a></code></b> displays all environment variables and their values. The command <b><code>printenv</code></b> can also be used to print a single variable by giving that variable name as the sole argument to the command.
</p>
<h3>DOS, OS/2 and Windows[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=4">edit</a>]</h3>
<p>In DOS, OS/2 and Windows command-line interpreters such as <code>COMMAND.COM</code> and <code>CMD.EXE</code>, an environment variable is retrieved by placing a <code>%</code> sign before and after it.
</p><p>In DOS, OS/2 and Windows command-line interpreters as well as their <a href="/wiki/API">API</a>, upper or lower case is not distinguished for environment variable names.
</p><p>The environment variable named <code>HOMEDRIVE</code> contains the drive letter (plus its trailing <code>:</code> colon) of the user's home directory, whilst <code>HOMEPATH</code> contains the full path of the user's home directory within that drive.
</p><p>So to see the home drive and path, the user may type this:
</p>
<div><pre>ECHO %HOMEDRIVE%%HOMEPATH%
</pre></div>
<p>The command <b><code>SET</code></b> (with no arguments) displays all environment variables and their values. <code>set</code> can also be used to print all variables whose name begins with a given prefix by giving the prefix as the sole argument to the command.
</p><p>In <a href="/wiki/Windows_PowerShell">Windows PowerShell</a>, the user may type any of the following:
</p>
<div><pre>echo $env:homedrive$env:homepath
Write-Output $env:homedrive$env:homepath
"$env:homedrive$env:homepath"
</pre></div>
<p>In PowerShell, upper or lower case is not distinguished for environment variable names.
</p><p>The following command displays all environment variables and their values:
</p>
<h3>Assignment: Unix[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=5">edit</a>]</h3>
<p>The commands <code>env</code> and <code>set</code> can be used to set environment variables and are often incorporated directly into the shell.
</p><p>The following commands can also be used, but are often dependent on a certain shell.
</p>
<pre><i>VARIABLE</i>=<i>value</i> #
export <i>VARIABLE</i> # for <a href="/wiki/Bourne_shell">Bourne</a> and related shells
</pre>
<pre>export <i>VARIABLE</i>=<i>value</i> # for <a href="/wiki/KornShell">ksh</a>, <a href="/wiki/Bash_(Unix_shell)">bash</a>, and related shells
</pre>
<pre>setenv <i>VARIABLE</i> <i>value</i> # for <a href="/wiki/C_shell">csh</a> and related shells
</pre>
<p>A few simple principles govern how environment variables achieve their effect.
</p><p>Environment variables are local to the process in which they were set. If two shell processes are spawned and the value of an environment variable is changed in one, that change will not be seen by the other.
</p><p>When a child process is created, it inherits all the environment variables and their values from the parent process. Usually, when a program calls another program, it first creates a child process by <a href="/wiki/Fork_(system_call)">forking</a>, then the child adjusts the environment as needed and lastly the child <a href="/wiki/Exec_(system_call)">replaces</a> itself with the program to be called. This procedure gives the calling program control over the environment of the called program.
</p><p>In Unix shells, variables may be assigned without the <b><code>export</code></b> keyword. Variables defined in this way are displayed by the <b><code>set</code></b> command, but are <em>not</em> true environment variables, as they are stored only by the shell and are unknown to all other processes. The <code>printenv</code> command will not display them, and child processes do not inherit them.
</p>
<pre><i>VARIABLE</i>=<i>value</i>
</pre>
<p>The prefix syntax exports a "true" environment variable to a child process without affecting the current process:<sup><a href="#cite_note-ClassicShS-1">[1]</a></sup>
</p>
<pre><i>VARIABLE</i>=<i>value</i> program_name [arguments]
</pre>
<p>The persistence of an environment variable can be session-wide or system-wide.
</p><p><b><code>unset</code></b> is a builtin command implemented by both the <a href="/wiki/Bourne_shell">Bourne shell</a> family (<code>sh</code>, <code>ksh</code>, <code>bash</code>, etc.) and the <a href="/wiki/C_shell">C shell</a> family (csh, tcsh, etc.) of <a href="/wiki/Unix_shell">Unix command line shells</a>. It unsets a shell variable, removing it from memory and the shell's exported environment. It is implemented as a <a href="/wiki/Shell_builtin">shell builtin</a>, because it directly manipulates the internals of the shell.<sup><a href="#cite_note-OG_unset-2">[2]</a></sup><sup><a href="#cite_note-Bash_unset-3">[3]</a></sup> Read-only shell variables cannot be unset. If one tries to unset a read-only variable, the <code>unset</code> command will print an error message and return a non-zero exit code.
</p>
<h3>Assignment: DOS, OS/2 and Windows[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=6">edit</a>]</h3>
<p>In DOS, OS/2 and Windows command-line interpreters such as <code>COMMAND.COM</code> and <code>CMD.EXE</code>, the <b><code><a href="/wiki/SET_(DOS_command)">SET</a></code></b> command is used to assign environment variables and values using the following arguments:
</p>
<pre>SET VARIABLE=value
</pre>
<p>An environment variable is removed via:
</p>
<pre>SET VARIABLE=
</pre>
<p>The <b><code>SET</code></b> command without any arguments displays all environment variables along with their values; <b><code>SET "0 or more spaces"</code></b> shows the internal ones too. In <code>CMD.EXE</code>, it is possible to assign local variables that do not leak outside using the <b><code>SETLOCAL</code></b> command.
</p><p>In <a href="/wiki/PowerShell">PowerShell</a>, the assignment follows a syntax similar to Unix:
</p>
<pre>$env:VARIABLE = "VALUE"
</pre>
<h2>Examples[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=7">edit</a>]</h2>
<p>Examples of environment variables include:
</p>
<ul><li><code><a href="/wiki/PATH_(variable)">PATH</a></code>: a list of directory paths. When the <a href="/wiki/User_(computing)">user</a> types a command without providing the full path, this list is checked to see whether it contains a path that leads to the command.</li>
<li><code>HOME</code> (<a href="/wiki/Unix-like">Unix-like</a>) and <code>USERPROFILE</code> (Microsoft Windows): indicate where a user's <a href="/wiki/Home_directory">home directory</a> is located in the <a href="/wiki/File_system">file system</a>.</li>
<li><code>HOME/{.AppName}</code> (<a href="/wiki/Unix-like">Unix-like</a>) and <code>APPDATA\{DeveloperName\AppName}</code> (Microsoft Windows): for storing application settings. Many applications incorrectly use <code>USERPROFILE</code> for application settings in Windows: <code>USERPROFILE</code> should only be used in dialogs that allow user to choose between paths like <code>Documents/Pictures/Downloads/Music</code>; for programmatic purposes, <code>APPDATA</code> (for roaming application settings shared across multiple devices), <code>LOCALAPPDATA</code> (for local application settings) or <code>PROGRAMDATA</code> (for application settings shared between multiple OS users) should be used.<sup><a href="#cite_note-appdata-4">[4]</a></sup></li>
<li><code>TERM</code> (<a href="/wiki/Unix-like">Unix-like</a>): specifies the type of <a href="/wiki/Computer_terminal">computer terminal</a> or <a href="/wiki/Terminal_emulator">terminal emulator</a> being used (e.g., <code><a href="/wiki/Vt100">vt100</a></code> or <code><a href="/wiki/Dumb_terminal">dumb</a></code>).</li>
<li><code>PS1</code> (<a href="/wiki/Unix-like">Unix-like</a>): specifies how the prompt is displayed in the <a href="/wiki/Bourne_shell">Bourne shell</a> and variants.</li>
<li><code>MAIL</code> (<a href="/wiki/Unix-like">Unix-like</a>): used to indicate where a user's mail is to be found.</li>
<li><code>TEMP</code>: location where processes can store temporary files.</li></ul>
<h2>True environment variables[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=8">edit</a>]</h2>
<h3>Unix[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=9">edit</a>]</h3>
<dl><dt><code>$PATH</code></dt>
<dd>Contains a colon-separated list of directories that the shell searches for commands that do not contain a slash in their name (commands with slashes are interpreted as file names to execute, and the shell attempts to execute the files directly). It is equivalent to the <a href="/wiki/DOS">DOS</a>, <a href="/wiki/OS/2">OS/2</a> and <a href="/wiki/Microsoft_Windows">Windows</a> <code><a href="#%PATH%">%PATH%</a></code> variable.</dd></dl>
<dl><dt><code>$HOME</code></dt>
<dd>Contains the location of the user's <a href="/wiki/Home_directory">home directory</a>. Although the current user's home directory can also be found out through the C-functions <code>getpwuid</code> and <code>getuid</code>, <code>$HOME</code> is often used for convenience in various shell scripts (and other contexts). Using the environment variable also gives the user the possibility to point to another directory.</dd></dl>
<dl><dt><code>$PWD</code></dt>
<dd>This variable points to the current directory. Equivalent to the output of the command pwd when called without arguments.</dd></dl>
<dl><dt><code>$DISPLAY</code></dt>
<dd>Contains the identifier for the display that <a href="/wiki/X11">X11</a> programs should use by default.</dd></dl>
<dl><dt><code>$LD_LIBRARY_PATH</code></dt>
<dd>On many Unix systems with a <a href="/wiki/Dynamic_linker">dynamic linker</a>, contains a colon-separated list of directories that the dynamic linker should search for <a href="/wiki/Shared_object">shared objects</a> when building a process image after <code>exec</code>, before searching in any other directories.</dd></dl>
<dl><dt><code>$LIBPATH</code> or <code>$SHLIB_PATH</code></dt>
<dd>Alternatives to <code>$LD_LIBRARY_PATH</code> typically used on older Unix versions.</dd></dl>
<dl><dt><code>$LANG, $LC_ALL, $LC_...</code></dt>
<dd><code>$LANG</code> is used to set to the default <a href="/wiki/Locale_(computer_software)">locale</a>. For example, if the locale values are <code>pt_BR</code>, then the language is set to (Brazilian) Portuguese and Brazilian practice is used where relevant. Different aspects of localization are controlled by individual <code>$LC_</code>-variables (<code>$LC_CTYPE</code>, <code>$LC_<a href="/wiki/Collation">COLLATE</a></code>, <code>$LC_DATE</code> etc.). <code>$LC_ALL</code> can be used to force the same locale for all aspects.</dd></dl>
<dl><dt><code>$TZ</code></dt>
<dd>Refers to <a href="/wiki/Time_zone">time zone</a>. It can be in several formats, either specifying the time zone itself or referencing a file (in <code>/usr/share/zoneinfo</code>).</dd></dl>
<dl><dt><code>$BROWSER</code></dt>
<dd>Contains a colon-separated list of a user's <a href="/wiki/Web_browser">web browser</a> preferences, for use by programs that need to allow the user to view content at a <a href="/wiki/URL">URL</a>. The browsers in the list are intended to be attempted from first to last, stopping after the first one that succeeds. This arrangement allows for fallback behavior in different environments, e.g., in an <a href="/wiki/X_Window_System">X11</a> environment, a graphical browser (such as <a href="/wiki/Firefox">Firefox</a>) can be used, but in a console environment a terminal-base browser (such a <a href="/wiki/Lynx_(web_browser)">Lynx</a>) can be used. A <code>%s</code> token may be present to specify where the URL should be placed; otherwise the browser should be launched with the URL as the first argument.<sup><a href="#cite_note-ESR_2002_BROWSER-5">[5]</a></sup><sup><a href="#cite_note-LWN_2001_BROWSER-6">[6]</a></sup><sup><a href="#cite_note-PERL_ENV_BROWSER-7">[7]</a></sup><sup><a href="#cite_note-PYTHON_WEBBROWSER-8">[8]</a></sup><sup><a href="#cite_note-DEBIAN_DFLT_WEB_BROWSER-9">[9]</a></sup></dd></dl>
<h3>DOS[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=10">edit</a>]</h3>
<p>
Under DOS, the <i>master environment</i> is provided by the primary command processor, which inherits the <i>pre-environment</i> defined in <code>CONFIG.SYS</code> when first loaded. Its size can be configured through the <code>COMMAND /E:n</code> parameter between 160<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> and 32767<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> bytes. <i>Local environment</i> segments inherited to child processes are typically reduced down to the size of the contents they hold. Some command-line processors (like <a href="/wiki/4DOS">4DOS</a>) allow to define a minimum amount of free environment space that will be available when launching secondary shells.<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> While the content of environment variables remains unchanged upon storage, their names (without the "<code>%</code>") are always converted to uppercase, with the exception of <i>pre-environment variables</i> defined via the <code><a href="/wiki/CONFIG.SYS">CONFIG.SYS</a></code> directive <code><a href="/wiki/SET_(CONFIG.SYS_directive)">SET</a></code> under <a href="/wiki/DR_DOS_6.0">DR DOS 6.0</a> and higher<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Paul_1997_4DOSTIP-12">[12]</a></sup> (and only with <code><a href="/wiki/SWITCHES_(CONFIG.SYS_directive)">SWITCHES=/L</a></code> (for "allow lowercase names") under <a href="/wiki/DR-DOS_7.02">DR-DOS 7.02</a> and higher).<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup><sup><a href="#cite_note-Paul_1997_OD-A3-13">[13]</a></sup> In principle, <a href="/wiki/MS-DOS_7.0">MS-DOS 7.0</a> and higher also supports lowercase variable names (<code><a href="#windir">%windir%</a></code>), but provides no means for the user to define them. Environment variable names containing lowercase letters are stored in the environment just like normal environment variables, but remain invisible to most DOS software, since they are written to expect uppercase variables only.<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup><sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Paul_1997_4DOSTIP-12">[12]</a></sup> Some command processors limit the maximum length of a variable name to 80 characters.<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> While principally only limited by the size of the <i>environment segment</i>, some DOS and 16-bit Windows programs<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup><sup><a href="#cite_note-NB_ENVLEN128-14">[nb 1]</a></sup> do not expect the contents of environment variables to exceed 128 characters. DR-DOS <code>COMMAND.COM</code> supports environment variables up to 255, <a href="/wiki/4DOS">4DOS</a> even up to 512 characters.<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> Since <code>COMMAND.COM</code> can be configured (via <code>/L:128..1024</code>) to support command lines up to 1024 characters internally under MS-DOS 7.0 and higher, environment variables should be expected to contain at least 1024 characters as well. In some versions of DR-DOS, the environment passed to drivers, which often do not need their environment after installation, can be shrunken or <a href="/wiki/Relocation_(computing)">relocated</a> through <code>SETENV</code> or <code><a href="/wiki/INSTALL_(CONFIG.SYS_directive)">INSTALL[HIGH]</a></code>/<code><a href="/wiki/LOADHIGH">LOADHIGH</a></code> options <code>/Z</code> (zero environment), <code>/D[:<a href="/wiki/Load_drive">loaddrive</a>]</code> (substitute drive, e.g. <code>B:TSR.COM</code>) and <code>/E</code> (relocate environment above program) in order to minimize the driver's effectively resulting resident memory footprint.<sup><a href="#cite_note-Paul_1997_SETENV-15">[14]</a></sup><sup><a href="#cite_note-Paul_1997_OD-A3-13">[13]</a></sup><sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Paul_2002_CTMOUSE-16">[15]</a></sup><sup><a href="#cite_note-PTS-DOS_2000-17">[16]</a></sup><sup><a href="#cite_note-Paul_2002_COM-18">[17]</a></sup>
</p><p>In batch mode, non-existent environment variables are replaced by a zero-length string.
</p><p><i>Standard environment variables</i> or <i>reserved environment variables</i> include:
</p>
<dl><dt><code>%APPEND%</code> (supported since DOS 3.3)</dt>
<dd>This variable contains a semicolon-delimited list of directories in which to search for files. It is usually changed via the <code><a href="/wiki/APPEND_(DOS_command)">APPEND</a> /E</code> command, which also ensures that the directory names are converted into uppercase. Some DOS software actually expects the names to be stored in uppercase and the length of the list not to exceed 121<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> characters, therefore the variable is best not modified via the <code><a href="/wiki/SET_(DOS_command)">SET</a></code> command. <a href="/wiki/Long_filename">Long filenames</a> containing spaces or other special characters must not be quoted (<code>"</code>).</dd></dl>
<dl><dt><code>%CONFIG%</code> (supported since <a href="/wiki/MS-DOS_6.0">MS-DOS 6.0</a> and <a href="/wiki/PC_DOS_6.1">PC DOS 6.1</a>, also supported by <a href="/wiki/Datalight_ROM-DOS">ROM-DOS</a><sup><a href="#cite_note-Datalight_2005_ROM-DOS-19">[18]</a></sup>)</dt>
<dd>This variable holds the symbolic name of the currently chosen boot configuration. It is set by the <a href="/wiki/DOS_BIOS">DOS BIOS</a> (<code><a href="/wiki/IO.SYS">IO.SYS</a></code>, <code><a href="/wiki/IBMBIO.COM">IBMBIO.COM</a></code>, etc.) to the name defined by the corresponding <code><a href="/wiki/CONFIG.SYS">CONFIG.SYS</a></code> directive <code><a href="/wiki/MENUITEM_(CONFIG.SYS_directive)">MENUITEM</a></code> before launching the primary command processor. Its main purpose is to allow further special cases in <code><a href="/wiki/AUTOEXEC.BAT">AUTOEXEC.BAT</a></code> and similar batchjobs depending on the selected option at boot time. This can be emulated under DR-DOS by utilizing the <code>CONFIG.SYS</code> directive <code><a href="/wiki/SET_(CONFIG.SYS_directive)">SET</a></code> like <code>SET CONFIG=1</code>.</dd></dl>
<dl><dt><code>%CMDLINE%</code> (introduced with <a href="/wiki/4DOS">4DOS</a>, also supported since <a href="/wiki/MS-DOS_7.0">MS-DOS 7.0</a>)</dt>
<dd>This variable contains the fully expanded text of the currently executing command line. It can be read by applications to detect the usage of and retrieve long command lines, since the traditional method to retrieve the command line arguments through the <a href="/wiki/Program_Segment_Prefix">PSP</a> (or related <a href="/wiki/Application_programming_interface">API</a> functions) is limited to 126 characters and is no longer available when <a href="/wiki/File_Control_Block">FCBs</a> get expanded or the default <a href="/wiki/Disk_Transfer_Area">DTA</a> is used. While 4DOS supports longer command lines, <code>COMMAND.COM</code> still only supports a maximum of 126 characters at the prompt by default (unless overridden with <code>/U:128..255</code> to specify the size of the command line buffer), but nevertheless internal command lines can become longer through f.e. variable expansion (depending on <code>/L:128..1024</code> to specify the size of the internal buffer). In addition to the command-line length byte in the PSP, the PSP command line is normally limited by <a href="/wiki/ASCII_13">ASCII-13</a>, and command lines longer than 126 characters will typically be truncated by having an ASCII-13 inserted at position 127,<sup><a href="#cite_note-Paul_1997_4DOSTIP-12">[12]</a></sup> but this cannot be relied upon in all scenarios.<sup><a href="#cite_note-Paul_1997_4DOSTIP-12">[12]</a></sup><sup><a href="#cite_note-NB_CMDLINE-20">[nb 2]</a></sup> The variable will be suppressed for external commands invoked with a preceding <code>@</code>-symbol like in <code>@XCOPY ...</code> for backward compatibility and in order to minimize the size of the environment when loading non-relocating <a href="/wiki/Terminate-and-stay-resident_program">terminate-and-stay-resident programs</a>. Some beta versions of <a href="/wiki/Windows_Chicago">Windows Chicago</a> used <code>%CMDLINE%</code> to store only the remainder of the command line excessing 126 characters instead of the complete command line.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Paul_1997_4DOSTIP-12">[12]</a></sup></dd></dl>
<dl><dt><code><a href="/wiki/COMSPEC_(environment_variable)">%COMSPEC%</a></code> (supported since DOS 2.0)</dt>
<dd>This variable contains the full <a href="/wiki/8.3_filename">8.3</a> path to the <a href="/wiki/Command_processor">command processor</a>, typically <code>C:\<a href="/wiki/COMMAND.COM">COMMAND.COM</a></code> or <code>C:\DOS\COMMAND.COM</code>. It must not contain <a href="/wiki/Long_filenames">long filenames</a>, but under DR-DOS it may contain <a href="/wiki/FAT_file_password">file</a> and <a href="/wiki/FAT_directory_password">directory passwords</a>. It is set up by the primary command processor to point to itself (typically reflecting the settings of the <code><a href="/wiki/CONFIG.SYS">CONFIG.SYS</a></code> directive <code><a href="/wiki/SHELL_(CONFIG.SYS_directive)">SHELL</a></code>), so that the resident portion of the command processor can reload its transient portion from disk after the execution of larger programs. The value can be changed at runtime to reflect changes in the configuration, which would require the command processor to reload itself from other locations. The variable is also used when launching secondary shells.</dd></dl>
<dl><dt><code>%COPYCMD%</code> (supported since <a href="/wiki/MS-DOS_6.2">MS-DOS 6.2</a> and <a href="/wiki/PC_DOS_6.3">PC DOS 6.3</a>, also supported by <a href="/wiki/Datalight_ROM-DOS">ROM-DOS</a><sup><a href="#cite_note-Datalight_2005_ROM-DOS-19">[18]</a></sup>)</dt>
<dd>Allows a user to specify the <code>/Y</code> switch (to assume "Yes" on queries) as the default for the <code><a href="/wiki/Copy_(command)">COPY</a></code>, <code><a href="/wiki/XCOPY">XCOPY</a></code>, and <code><a href="/wiki/Move_(command)">MOVE</a></code> commands. A default of <code>/Y</code> can be overridden by supplying the <code>/-Y</code> switch on the command line. The <code>/Y</code> switch instructs the command to replace existing files without prompting for confirmation.</dd></dl>
<dl><dt><code>%DIRCMD%</code> (supported since <a href="/wiki/MS-DOS_5.0">MS-DOS 5.0</a> and <a href="/wiki/IBM_DOS_5.0">PC DOS 5.0</a>, also supported by <a href="/wiki/Datalight_ROM-DOS">ROM-DOS</a><sup><a href="#cite_note-Datalight_2005_ROM-DOS-19">[18]</a></sup>)</dt>
<dd>Allows a user to specify customized default parameters for the <code><a href="/wiki/Dir_(command)">DIR</a></code> command, including file specifications. Preset default switches can be overridden by providing the negative switch on the command line. For example, if <code>%DIRCMD%</code> contains the <code>/W</code> switch, then it can be overridden by using <code>DIR /-W</code> at the command line. This is similar to the environment variable <code><a href="#%$DIR%">%$DIR%</a></code> under <a href="/wiki/DOS_Plus">DOS Plus</a><sup><a href="#cite_note-Kotulla_1987_Environment-21">[19]</a></sup> and a facility to define default switches for <code>DIR</code> through its <code>/C</code> or <code>/R</code> switches under <a href="/wiki/DR-DOS">DR-DOS</a> <code>COMMAND.COM</code>.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup> <code>%DIRCMD%</code> is also supported by the external <code>SDIR.COM</code>/<code>DIR.COM</code> <a href="/wiki/Stacker_(disk_compression)">Stacker</a> commands under <a href="/wiki/Novell_DOS_7">Novell DOS 7</a> and higher.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup></dd></dl>
<dl><dt><code>%LANG%</code> (supported since <a href="/wiki/MS-DOS_7.0">MS-DOS 7.0</a>)</dt>
<dd>This variable is supported by some tools to switch the locale for messages in multilingual issues.</dd></dl>
<dl><dt><code>%LANGSPEC%</code> (supported since <a href="/wiki/MS-DOS_7.0">MS-DOS 7.0</a>)</dt>
<dd>This variable is supported by some tools to switch the locale for messages in multilingual issues.</dd></dl>
<dl><dt><code>%NO_SEP%</code> (supported since <a href="/wiki/PC_DOS_6.3">PC DOS 6.3</a> and <a href="/wiki/DR-DOS_7.07">DR-DOS 7.07</a>)</dt>
<dd>This variable controls the display of <a href="/wiki/Decimal_separator#Digit_grouping">thousands-separators</a> in messages of various commands. Issued by default, they can be suppressed by specifying <code>SET NO_SEP=ON</code> or <code>SET NO_SEP=1</code> under PC DOS. DR-DOS additionally allows to override the system's thousands-separator displayed as in f.e. <code>SET NO_SEP=.</code>.<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup></dd></dl>
<dl><dt><code><a href="/wiki/PATH_(environment_variable)">%PATH%</a></code> (supported since DOS 2.0)</dt>
<dd>This variable contains a semicolon-delimited list of directories in which the <a href="/wiki/Command_interpreter">command interpreter</a> will search for <a href="/wiki/Executable_file">executable files</a>. Equivalent to the Unix <code><a href="#$PATH">$PATH</a></code> variable (but some DOS and Windows applications also use the list to search for data files similar to <code><a href="#$LD_LIBRARY_PATH">$LD_LIBRARY_PATH</a></code> on Unix-like systems). It is usually changed via the <code><a href="/wiki/PATH_(DOS_command)">PATH</a></code> (or <code>PATH /E</code> under <a href="/wiki/MS-DOS_6.0">MS-DOS 6.0</a>) command, which also ensures that the directory names are converted into uppercase. Some DOS software actually expects the names to be stored in uppercase and the length of the list not to exceed 123<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> characters,<sup><a href="#cite_note-NB_ENVLEN128-14">[nb 1]</a></sup> therefore the variable should better not be modified via the <code><a href="/wiki/SET_(DOS_command)">SET</a></code> command.<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> <a href="/wiki/Long_filename">Long filenames</a> containing spaces or other special characters must not be quoted (<code>"</code>). By default, the current directory is searched first, but some command-line processors like <a href="/wiki/4DOS">4DOS</a> allow "<code>.</code>" (for "current directory") to be included in the list as well in order to override this search order; some DOS programs are incompatible with this extension.<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup></dd></dl>
<dl><dt><code>%PROMPT%</code> (supported since DOS 2.0)</dt>
<dd>This variable contains a <code>$</code>-tokenized string defining the display of the <a href="/wiki/Prompt_(computing)">prompt</a>. It is usually changed via the <code><a href="/wiki/PROMPT_(DOS_command)">PROMPT</a></code> command.</dd></dl>
<dl><dt><code>%TEMP%</code> (and <code>%TMP%</code>)</dt>
<dd>These variables contain the path to the directory where <a href="/wiki/Temporary_file">temporary files</a> should be stored. Operating system tools typically only use <code>%TEMP%</code>, whereas third-party programs also use <code>%TMP%</code>. Typically <code>%TEMP%</code> takes precedence over <code>%TMP%</code>.</dd></dl>
<p>The <a href="/wiki/DR-DOS">DR-DOS</a> family supports a number of additional <i>standard environment variables</i> including:
</p>
<dl><dt><code>%BETA%</code></dt>
<dd>This variable contains an optional message displayed by some versions (including <a href="/wiki/DR_DOS_3.41">DR DOS 3.41</a>) of <code>COMMAND.COM</code> at the startup of secondary shells.<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup></dd></dl>
<dl><dt><code>%DRDOSCFG%</code>/<code>%NWDOSCFG%</code>/<code>%OPENDOSCFG%</code></dt>
<dd>This variable contains the directory<sup><a href="#cite_note-Caldera_1998_USER-23">[21]</a></sup> (without trailing "<code>\</code>") where to search for <code>.INI</code> and <code>.CFG</code> configuration files (that is, DR-DOS application specific files like <code>TASKMGR.INI</code>, <code>TASKMAX.INI</code>, <code><a href="/wiki/VIEWMAX.INI">VIEWMAX.INI</a></code>, <code>FASTBACK.CFG</code> etc., class specific files like <code>COLORS.INI</code>, or global files like <code><a href="/wiki/DRDOS.INI">DRDOS.INI</a></code>, <code><a href="/wiki/NWDOS.INI">NWDOS.INI</a></code>, <code><a href="/wiki/OPENDOS.INI">OPENDOS.INI</a></code>, or <code><a href="/wiki/DOS.INI">DOS.INI</a></code>), as used by the <code>INSTALL</code> and <code>SETUP</code> commands and various DR-DOS programs like <code>DISKOPT</code>, <code>DOSBOOK</code>, <code>EDIT</code>, <code>FBX</code>, <code>FILELINK</code>, <code>LOCK</code>, <code>SECURITY.OVL</code>/<code>NWLOGIN.EXE</code>, <code>SERNO</code>, <code>TASKMAX</code>, <code>TASKMGR</code>, <code><a href="/wiki/VIEWMAX">VIEWMAX</a></code>, or <code>UNDELETE</code>.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup> It must not contain <a href="/wiki/Long_filename">long filenames</a>.</dd></dl>
<dl><dt><code>%DRCOMSPEC%</code></dt>
<dd>This variable optionally holds an alternative path to the command processor taking precedence over the path defined in the <code>%COMSPEC%</code> variable, optionally including <a href="/wiki/FAT_file_password">file</a> and <a href="/wiki/FAT_directory_password">directory passwords</a>. Alternatively, it can hold a special value of "<code>ON</code>" or "<code>1</code>" in order to enforce the usage of the <code>%COMSPEC%</code> variable even in scenarios where the <code>%COMSPEC%</code> variable may point to the wrong command-line processor, for example, when running some versions of the DR-DOS <code><a href="/wiki/SYS_(command)">SYS</a></code> command under a foreign operating system.<sup><a href="#cite_note-Paul_2017-24">[22]</a></sup></dd></dl>
<dl><dt><code>%DRSYS%</code></dt>
<dd>Setting this variable to "<code>ON</code>" or "<code>1</code>" will force some versions of the DR-DOS <code><a href="/wiki/SYS_(command)">SYS</a></code> command to work under foreign operating systems instead of displaying a warning.<sup><a href="#cite_note-Paul_2017-24">[22]</a></sup></dd></dl>
<dl><dt><code>%FBP_USER%</code></dt>
<dd>Specifies the user name used by the <a href="/wiki/FastBack">FastBack</a> command <code><a href="/wiki/FBX_(DOS_command)">FBX</a></code> and <code>{user}<a href="/wiki/.FB">.FB</a></code> configuration files under <a href="/wiki/Novell_DOS_7">Novell DOS 7</a>.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup></dd></dl>
<dl><dt><code>%HOMEDIR%</code></dt>
<dd>This variable may contain the home directory under DR-DOS (including <a href="/wiki/DR_DOS_5.0">DR DOS 5.0</a> and <a href="/wiki/DR_DOS_6.0">6.0</a>).<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup></dd></dl>
<dl><dt><code>%INFO%</code></dt>
<dd>In some versions of DR-DOS <code>COMMAND.COM</code> this variable defines the string displayed by the <code>$I</code> token of the <code><a href="/wiki/PROMPT_(DOS_command)">PROMPT</a></code> command.<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup> It can be used, for example, to inform the user how to exit secondary shells.</dd></dl>
<dl><dt><code>%LOGINNAME%</code></dt>
<dd>In some versions of DR-DOS <code>COMMAND.COM</code> this variable defines the user name displayed by the <code>$U</code> token of the <code><a href="/wiki/PROMPT_(DOS_command)">PROMPT</a></code> command, as set up by f.e. login scripts for <a href="/wiki/Novell_NetWare">Novell NetWare</a>.<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup><sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup> See also the similarly named pseudo-variable <code><a href="#%LOGIN_NAME%">%LOGIN_NAME%</a></code>.</dd></dl>
<dl><dt><code>%MDOS_EXEC%</code></dt>
<dd>This variable can take the values "<code>ON</code>" or "<code>OFF</code>" under <a href="/wiki/Multiuser_DOS">Multiuser DOS</a>. If enabled, the operating system permits applications to shell out to secondary shells with the <a href="/w/index.php?title=DOS_Program_Area&amp;action=edit&amp;redlink=1">DOS Program Area</a> (DPA) freed in order to have maximum DOS memory available for secondary applications instead of running them in the same domain as under DOS.<sup><a href="#cite_note-CCI_1997_HELP-25">[23]</a></sup><sup><a href="#cite_note-CCI_1997_PRINTDOC-26">[24]</a></sup></dd></dl>
<dl><dt><code>%NOCHAR%</code></dt>
<dd>This variable can be used to define the character displayed by some commands in messages for "No" in <code>[Y,N]</code> queries, thereby overriding the current system default (typically "<code>N</code>" in English versions of DR-DOS). If it contains a string, only the first character, uppercased, will be taken. Some commands also support a command line parameter <code>/Y</code> to automatically assume "Yes" on queries, thereby suppressing such prompts. If, however, the parameter <code>/Y:yn</code> is used to specify the "Yes"/"No" characters (thereby overriding any <code>%NOCHAR%</code> setting), queries are not suppressed. See also the related <code>CONFIG.SYS</code> directive <code><a href="/wiki/NOCHAR_(CONFIG.SYS_directive)">NOCHAR</a></code> and the environment variable <code><a href="#%YESCHAR%">%YESCHAR%</a></code>.<sup><a href="#cite_note-Paul_2017-24">[22]</a></sup></dd></dl>
<dl><dt><code>%NOSOUND%</code></dt>
<dd>Setting this variable to "<code>ON</code>" or "<code>1</code>" will disable default beeps issued by some DR-DOS commands in certain situations such as to inform the user of the completion of some operation, that user interaction is required, or when a wrong key was pressed. Command line options to specifically enable certain beeps will override this setting.</dd></dl>
<dl><dt><code>%OS%</code></dt>
<dd>This variable contains the name of the operating system in order to distinguish between different DOS-related operating systems of <a href="/wiki/Digital_Research">Digital Research</a>-origin in batch jobs and applications.<sup><a href="#cite_note-Caldera_1998_USER-23">[21]</a></sup> Known values include "<code>DOSPLUS</code>" (<a href="/wiki/DOS_Plus_1.2">DOS Plus 1.2</a> in DOS emulation), "<code>CPCDOS 4.1</code>" (DOS Plus 1.2 in <a href="/wiki/CP/M">CP/M</a> emulation), "<code>DRDOS</code>" (<a href="/wiki/DR_DOS_3.31">DR DOS 3.31</a>-<a href="/wiki/DR_DOS_6.0">6.0</a>, <a href="/wiki/DR_DOS_Panther">DR DOS Panther</a>, <a href="/wiki/DR_DOS_StarTrek">DR DOS StarTrek</a>, <a href="/wiki/DR-DOS_7.02">DR-DOS 7.02</a><sup><a href="#cite_note-Caldera_1998_USER-23">[21]</a></sup>-<a href="/wiki/DR-DOS_7.05">7.05</a>), "<code>EZDOS</code>" (<a href="/wiki/EZ-DOS_3.41">EZ-DOS 3.41</a>), "<code>PALMDOS</code>" and "<code>NetWare PalmDOS</code>" (<a href="/wiki/PalmDOS_1.0">PalmDOS 1.0</a>), "<code>NWDOS</code>" (<a href="/wiki/Novell_DOS_7">Novell DOS 7</a>), "<code>NWDOS7</code>" (Novell DOS 7 Beta), "<code>OPENDOS</code>" (<a href="/wiki/Caldera_OpenDOS_7.01">Caldera OpenDOS 7.01</a>, <a href="/wiki/Caldera_DR-OpenDOS_7.02">Caldera DR-OpenDOS 7.02</a>), "<code>CDOS</code>" (<a href="/wiki/Concurrent_DOS">Concurrent DOS</a>, <a href="/wiki/Concurrent_DOS_XM">Concurrent DOS XM</a>), "<code>CPCDOS</code>" (<a href="/wiki/Concurrent_PC_DOS">Concurrent PC DOS</a>), "<code>CDOS386</code>" (<a href="/wiki/Concurrent_DOS_386">Concurrent DOS 386</a>), "<code>DRMDOS</code>" (<a href="/wiki/DR_Multiuser_DOS">DR Multiuser DOS</a>), "<code>MDOS</code>" (<a href="/wiki/CCI_Multiuser_DOS">CCI Multiuser DOS</a>),<sup><a href="#cite_note-CCI_1997_HELP-25">[23]</a></sup> "<code>IMSMDOS</code>" (<a href="/wiki/IMS_Multiuser_DOS">IMS Multiuser DOS</a>), "<code>REAL32</code>" (<a href="/wiki/REAL/32">REAL/32</a>).<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Paul_2002_OS-27">[25]</a></sup> MS-DOS <code><a href="/wiki/INTERSVR_(DOS_command)">INTERSVR</a></code> looks for a value of "<code>DRDOS</code>" as well.<sup><a href="#cite_note-Paul_2002_OS-27">[25]</a></sup> See also the identically named environment variable <code><a href="#OS">%OS%</a></code> later introduced in the <a href="/wiki/Windows_NT_family">Windows NT family</a>.</dd></dl>
<dl><dt><code>%PEXEC%</code></dt>
<dd>In some versions of DR-DOS this variable defines the command executed by the <code>$X</code> token of the <code><a href="/wiki/PROMPT_(DOS_command)">PROMPT</a></code> command before <code>COMMAND.COM</code> displays the prompt after returning from external program execution.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Caldera_1998_USER-23">[21]</a></sup></dd></dl>
<dl><dt><code>%SWITCHAR%</code></dt>
<dd>This variable defines the <a href="/wiki/SwitChar">SwitChar</a> to be used for argument parsing by some DR-DOS commands. If defined, it overrides the system's current SwitChar setting. The only accepted characters are "<code>/</code>" (DOS style), "<code>-</code>" (Unix style) and "<code>[</code>" (CP/M style). See also the related <code>CONFIG.SYS</code> directive <code><a href="/wiki/SWITCHAR_(CONFIG.SYS_directive)">SWITCHAR</a></code> (to set the system's SwitChar setting) and the <code><a href="#%/%">%/%</a></code> <i>system information variable</i> in some issues of DR-DOS <code>COMMAND.COM</code> (to retrieve the current setting for portable batchjobs).</dd></dl>
<dl><dt><code>%TASKMGRWINDIR%</code></dt>
<dd>This variable specifies the directory, where the <a href="/wiki/Windows">Windows</a> <code><a href="/wiki/SYSTEM.INI">SYSTEM.INI</a></code> to be used by the DR-DOS <code>TASKMGR</code> multitasker is located, overriding the default procedure to locate the file.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup></dd></dl>
<dl><dt><code>%VER%</code></dt>
<dd>This variable contains the version of the operating system in order to distinguish between different versions of DR-DOS in batch jobs and in the display of the <code><a href="/wiki/Ver_(command)">VER</a></code> command.<sup><a href="#cite_note-Caldera_1998_USER-23">[21]</a></sup> It is also used for the <code>$V</code> token of the <code><a href="/wiki/PROMPT_(DOS_command)">PROMPT</a></code> command and affects the value returned by the <i>system information variable</i> <code><a href="#%OS_VERSION%">%OS_VERSION%</a></code>. Known values include "<code>1.0</code>" (<a href="/wiki/PalmDOS_1.0">PalmDOS 1.0</a>), "<code>1.2</code>" (<a href="/wiki/DOS_Plus_1.2">DOS Plus 1.2</a> in DOS emulation), "<code>2.0</code>" (<a href="/wiki/Concurrent_DOS_386_2.0">Concurrent DOS 386 2.0</a>), "<code>3.0</code>" (<a href="/wiki/Concurrent_DOS_386_3.0">Concurrent DOS 386 3.0</a>), "<code>3.31</code>" (<a href="/wiki/DR_DOS_3.31">DR DOS 3.31</a>), "<code>3.32</code>" (<a href="/wiki/DR_DOS_3.32">DR DOS 3.32</a>), "<code>3.33</code>" (<a href="/wiki/DR_DOS_3.33">DR DOS 3.33</a>), "<code>3.34</code>" (<a href="/wiki/DR_DOS_3.34">DR DOS 3.34</a>), "<code>3.35</code>" (<a href="/wiki/DR_DOS_3.35">DR DOS 3.35</a>), "<code>3.40</code>" (<a href="/wiki/DR_DOS_3.40">DR DOS 3.40</a>), "<code>3.41</code>" (<a href="/wiki/DR_DOS_3.41">DR DOS 3.41</a>, <a href="/wiki/EZ-DOS_3.41">EZ-DOS 3.41</a>), "<code>3.41T</code>" (<a href="/wiki/DR_DOS_3.41T">DR DOS 3.41T</a>), "<code>4.1</code>" (<a href="/wiki/Concurrent_PC_DOS_4.1">Concurrent PC DOS 4.1</a>), "<code>5.0</code>" (<a href="/wiki/DR_DOS_5.0">DR DOS 5.0</a>, <a href="/wiki/DR_Multiuser_DOS_5.0">DR Multiuser DOS 5.0</a>), "<code>5.1</code>" (<a href="/wiki/Novell_DR_Multiuser_DOS_5.1">Novell DR Multiuser DOS 5.1</a>), "<code>6.0</code>" (<a href="/wiki/DR_Concurrent_DOS_XM_6.0">DR Concurrent DOS XM 6.0</a>, <a href="/wiki/DR_DOS_6.0">DR DOS 6.0</a>), "<code>6.2</code>" (<a href="/wiki/DR_Concurrent_DOS_XM_6.2">DR Concurrent DOS XM 6.2</a>), "<code>7</code>" (<a href="/wiki/Novell_DOS_7">Novell DOS 7</a>, <a href="/wiki/Caldera_OpenDOS_7.01">Caldera OpenDOS 7.01</a>, <a href="/wiki/DR-DOS_7.02">DR-DOS 7.02</a>-<a href="/wiki/DR-DOS_7.05">7.05</a>), "<code>7.00</code>" (<a href="/wiki/CCI_Multiuser_DOS_7.00">CCI Multiuser DOS 7.00</a>), "<code>7.07</code>" (<a href="/wiki/DR-DOS_7.07">DR-DOS 7.07</a>), "<code>7.1</code>" (<a href="/wiki/IMS_Multiuser_DOS_7.1">IMS Multiuser DOS 7.1</a>), "<code>7.21</code>" (<a href="/wiki/CCI_Multiuser_DOS_7.21">CCI Multiuser DOS 7.21</a>),<sup><a href="#cite_note-CCI_1997_HELP-25">[23]</a></sup> "<code>7.22</code>" (<a href="/wiki/CCI_Multiuser_DOS_7.22">CCI Multiuser DOS 7.22</a>) etc.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Paul_2002_OS-27">[25]</a></sup><sup><a href="#cite_note-CCI_1997_HELP-25">[23]</a></sup></dd></dl>
<dl><dt><code>%YESCHAR%</code></dt>
<dd>This variable can be used to define the character displayed by some commands in messages for "Yes" in <code>[Y,N]</code> queries, thereby overriding the current system default (typically "<code>Y</code>" in English versions of DR-DOS). If it contains a string, only the first character, uppercased, will be taken. Some commands also support a command line parameter <code>/Y</code> to automatically assume "Yes" on queries, thereby suppressing such prompts. If, however, the parameter <code>/Y:y</code> is used to specify the "Yes" character (thereby overriding any <code>%YESCHAR%</code> setting), queries are not suppressed. See also the related <code>CONFIG.SYS</code> directive <code><a href="/wiki/YESCHAR_(CONFIG.SYS_directive)">YESCHAR</a></code> and the environment variable <code><a href="#%NOCHAR%">%NOCHAR%</a></code>.<sup><a href="#cite_note-Paul_2017-24">[22]</a></sup></dd></dl>
<dl><dt><code>%$CLS%</code></dt>
<dd>This variable defines the control sequence to be sent to the console driver to clear the screen when the <code><a href="/wiki/CLS_(command)">CLS</a></code> command is issued, thereby overriding the internal default ("<code>←[2J</code>" under DR-DOS, "<code>←E</code>" under <a href="/wiki/DOS_Plus_1.2">DOS Plus 1.2</a> on Amstrad machines<sup><a href="#cite_note-Kotulla_1987_Environment-21">[19]</a></sup> as well as under <a href="/wiki/Concurrent_DOS">Concurrent DOS</a>, <a href="/wiki/Multiuser_DOS">Multiuser DOS</a>, and <a href="/wiki/REAL/32">REAL/32</a> for <a href="/wiki/VT52">VT52</a> terminals, or "<code>←+</code>" under Multiuser DOS for <a href="/wiki/ASCII">ASCII</a> terminals).<sup><a href="#cite_note-CCI_1997_HELP-25">[23]</a></sup> If the variable is not defined and no <code><a href="/wiki/ANSI.SYS">ANSI.SYS</a></code> console driver is detected, the DR-DOS <code>COMMAND.COM</code> will directly clear the screen via <code>INT 10h/AH=00h</code> <a href="/wiki/PC_BIOS">BIOS</a> function, like MS-DOS/PC DOS <code>COMMAND.COM</code> does. A special <code>\nnn</code>-notation for <a href="/wiki/Octal_number">octal numbers</a> is supported to allow the definition of special characters like ESC (<a href="/wiki/ASCII_27">ASCII-27</a> = "←" = 1Bh = 33o), as f.e. in <code>SET $CLS=\033[2J</code>. To send the backslash ("<code>\</code>") itself, it can be doubled "<code>\\</code>".<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup><sup><a href="#cite_note-CCI_1997_HELP-25">[23]</a></sup></dd></dl>
<dl><dt><code>%$DIR%</code></dt>
<dd>Supported by <a href="/wiki/DOS_Plus">DOS Plus</a> accepting the values "L" (long) or "W" (wide) to change the default layout of directory listings with <a href="/wiki/Dir_(command)">DIR</a>. Can be overridden using the command line options <code>/L</code> or <code>/W</code>.<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup><sup><a href="#cite_note-Kotulla_1987_Environment-21">[19]</a></sup> See also the similar environment variable <code><a href="#%DIRCMD%">%DIRCMD%</a></code> and the <code>DIR</code> options <code>/C</code> and <code>/R</code> of the DR-DOS COMMAND.COM.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup></dd></dl>
<dl><dt><code>%$PAGE%</code></dt>
<dd>Supported by <a href="/wiki/DOS_Plus">DOS Plus</a> accepting the values "<code>ON</code>" or "<code>OFF</code>" for pagination control. Setting this to "<code>ON</code>" has the same affect as adding <code>/P</code> to commands supporting it (like <a href="/wiki/Dir_(command)">DIR</a> or <a href="/wiki/TYPE_(DOS_command)">TYPE</a>).<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup><sup><a href="#cite_note-Kotulla_1987_Environment-21">[19]</a></sup></dd></dl>
<dl><dt><code>%$LENGTH%</code></dt>
<dd>Used by <a href="/wiki/DOS_Plus">DOS Plus</a> to define the screen length of the console in lines. This is used to control in a portable way when the screen output should be temporarily halted until a key is pressed in conjunction with the <code>/P</code> option supported by various commands or with automatic pagnination.<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup><sup><a href="#cite_note-Kotulla_1987_Environment-21">[19]</a></sup> See also the related environment variables <code><a href="#%$WIDTH%">%$WIDTH%</a></code> and <code><a href="#%DIRSIZE%">%DIRSIZE%</a></code> as well as the similar pseudo-variable <code><a href="#%_ROWS%">%_ROWS%</a></code>.</dd></dl>
<dl><dt><code>%$WIDTH%</code></dt>
<dd>Used by <a href="/wiki/DOS_Plus">DOS Plus</a> to define the screen width of the console in columns. This is used to control in a portable way the formatting of the screen output of commands like <code><a href="/wiki/Dir_(command)">DIR</a> /W</code> or <code><a href="/wiki/TYPE_(DOS_command)">TYPE</a> filename</code>.<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup><sup><a href="#cite_note-Kotulla_1987_Environment-21">[19]</a></sup> See also the related environment variables <code><a href="#%$LENGTH%">%$LENGTH%</a></code> and <code><a href="#%DIRSIZE%">%DIRSIZE%</a></code> as well as the similar pseudo-variable <code><a href="#%_COLUMNS%">%_COLUMNS%</a></code>.</dd></dl>
<dl><dt><code>%$SLICE%</code></dt>
<dd>Used by <a href="/wiki/DOS_Plus">DOS Plus</a> accepting a numerical value to control the foreground/background time slicing of multitasking programs.<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup><sup><a href="#cite_note-Kotulla_1987_Environment-21">[19]</a></sup> See also the DOS Plus command <code><a href="/wiki/SLICE_(DOS_command)">SLICE</a></code>.</dd></dl>
<dl><dt><code>%$ON%</code></dt>
<dd>This variable can hold an optional control sequence to switch text highlighting, reversion or colorization on. It is used to emphasize or otherwise control the display of the file names in commands like <code><a href="/wiki/TYPE_(DOS_command)">TYPE</a> wildcard</code>, for example <code>SET $ON=\033[1m</code> with <a href="/wiki/ANSI.SYS">ANSI.SYS</a> loaded or <code>SET $ON=\016</code> for an IBM or <a href="/wiki/ESC/P">ESC/P</a> printer. For the special <code>\nnn</code> octal notation supported, see <code><a href="#%$CLS%">%$CLS%</a></code>.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Kotulla_1987_Environment-21">[19]</a></sup> While the variable is undefined by default under DOS Plus and DR-DOS, the <a href="/wiki/Multiuser_DOS">Multiuser DOS</a> default for an <a href="/wiki/ASCII">ASCII</a> terminal equals <code>SET $ON=\033p</code>.<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup><sup><a href="#cite_note-CCI_1997_HELP-25">[23]</a></sup> See also the related environment variable <code><a href="#%$OFF%">%$OFF%</a></code>.</dd></dl>
<dl><dt><code>%$OFF%</code></dt>
<dd>This variable can hold an optional control sequence to switch text highlighting, reversion or colorization off. It is used to return to the normal output after the display of file names in commands like <code><a href="/wiki/TYPE_(DOS_command)">TYPE</a> wildcard</code>, for example <code>SET $OFF=\033[0m</code> with <a href="/wiki/ANSI.SYS">ANSI.SYS</a> loaded or <code>SET $OFF=\024</code> for an IBM or <a href="/wiki/ESC/P">ESC/P</a> printer. For the special <code>\nnn</code> octal notation supported, see <code><a href="#%$CLS%">%$CLS%</a></code>.<sup><a href="#cite_note-Paul_1997_NWDOSTIP-11">[11]</a></sup><sup><a href="#cite_note-Kotulla_1987_Environment-21">[19]</a></sup> While the variable is undefined by default under DOS Plus and DR-DOS, the <a href="/wiki/Multiuser_DOS">Multiuser DOS</a> default for an <a href="/wiki/ASCII">ASCII</a> terminal equals <code>SET $OFF=\033q</code>.<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup><sup><a href="#cite_note-CCI_1997_HELP-25">[23]</a></sup> See also the related environment variable <code><a href="#%$ON%">%$ON%</a></code>.</dd></dl>
<dl><dt><code>%$HEADER%</code></dt>
<dd>This variable can hold an optional control sequence issued before the output of the file contents in commands like <code><a href="/wiki/TYPE_(DOS_command)">TYPE</a></code> under DR-DOS 7.02 and higher. It can be used for highlighting, pagination or formatting, f.e. when sending the output to a printer, i.e. <code>SET $HEADER=\017</code> for an IBM or <a href="/wiki/ESC/P">ESC/P</a> printer. For the special <code>\nnn</code> octal notation supported, see <code><a href="#%$CLS%">%$CLS%</a></code>.<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup> See also the related environment variable <code><a href="#%$FOOTER%">%$FOOTER%</a></code>.</dd></dl>
<dl><dt><code>%$FOOTER%</code></dt>
<dd>This variable can hold an optional control sequence issued after the output of the file contents in commands like <code><a href="/wiki/TYPE_(DOS_command)">TYPE</a></code> under DR-DOS 7.02 and higher. It is used to return to the normal output format, i.e. <code>SET $FOOTER=\022\014</code> in the printer example above. For the special <code>\nnn</code> octal notation supported, see <code><a href="#%$CLS%">%$CLS%</a></code>.<sup><a href="#cite_note-Paul_2002_CLS-22">[20]</a></sup> See also the related environment variable <code><a href="#%$HEADER%">%$HEADER%</a></code>.</dd></dl>
<p><a href="/wiki/Datalight_ROM-DOS">Datalight ROM-DOS</a> supports a number of additional <i>standard environment variables</i> as well including:
</p>
<dl><dt><code>%DIRSIZE%</code></dt>
<dd>This variable is used to define non-standard screen sizes <code>rows[,cols]</code> for <code><a href="/wiki/DIR_(DOS_command)">DIR</a></code> options <code>/P</code> and <code>/W</code> (similar to <code><a href="#%$LENGTH%">%$LENGTH%</a></code> and <code><a href="#%$WIDTH%">%$WIDTH%</a></code> under DOS Plus).<sup><a href="#cite_note-Datalight_2005_ROM-DOS-19">[18]</a></sup></dd></dl>
<dl><dt><code>%NEWFILE%</code></dt>
<dd>This variable is automatically set to the first parameter given to the CONFIG.SYS directive <a href="/wiki/NEWFILE_(CONFIG.SYS_directive)">NEWFILE</a>.<sup><a href="#cite_note-Datalight_2005_ROM-DOS-19">[18]</a></sup></dd></dl>
<p><code>%TZ%</code>, <code>%COMM%</code>, <code>%SOCKETS%</code>, <code>%HTTP_DIR%</code>, <code>%HOSTNAME%</code> and <code>%FTPDIR%</code> are also used by ROM-DOS.<sup><a href="#cite_note-Datalight_2005_ROM-DOS-19">[18]</a></sup>
</p>
<h3>OS/2[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=11">edit</a>]</h3>
<dl><dt><code>%BEGINLIBPATH%</code></dt>
<dd>Contains a semicolon-separated list of directories which are searched for <a href="/wiki/Dynamic-link_library">DLLs</a> <i>before</i> the directories given by the <code><a href="/wiki/LIBPATH">%LIBPATH%</a></code> variable (which is set during system startup with the special <a href="/wiki/CONFIG.SYS">CONFIG.SYS</a> directive <code><a href="/wiki/LIBPATH_(CONFIG.SYS_directive)">LIBPATH</a></code>). It is possible to specify relative directories here, including "<code>.</code>" for the current working directory. See also the related environment variable <code><a href="#ENDLIBPATH">%ENDLIBPATH%</a></code>.</dd></dl>
<dl><dt><code>%ENDLIBPATH%</code></dt>
<dd>a list of directories to be searched for <a href="/wiki/Dynamic-link_library">DLLs</a> like <code><a href="#BEGINLIBPATH">%BEGINLIBPATH%</a></code>, but searched <i>after</i> the list of directories in <code><a href="/wiki/LIBPATH">%LIBPATH%</a></code>.</dd></dl>
<h3>Windows[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=12">edit</a>]</h3>
<p><i>System path variables</i><sup>[<i><a href="/wiki/Wikipedia:Citation_needed">citation needed</a></i>]</sup> refer to locations of critical operating system resources, and as such generally are not user-dependent.
</p>
<dl><dt><code>%APPDATA%</code></dt>
<dd>Contains the full path to the <i><a href="/wiki/Special_folder">Application Data</a></i> directory of the logged-in user. Does not work on Windows NT 4.0 SP6 UK.</dd></dl>
<dl><dt><code>%LOCALAPPDATA%</code></dt>
<dd>This variable is the temporary files of <i>Applications</i>. Its uses include storing of <a href="/wiki/Theme_(computing)">desktop themes</a>, <a href="/wiki/Windows_error_reporting">Windows error reporting</a>, caching and profiles of web browsers.</dd></dl>
<dl><dt><code>%<a href="/wiki/ComSpec">ComSpec</a>%</code>/<code>%<a href="/wiki/COMSPEC">COMSPEC</a>%</code></dt>
<dd>The <code>%ComSpec%</code> variable contains the full path to the command processor; on the Windows NT family of operating systems, this is <a href="/wiki/Cmd.exe">cmd.exe</a>, while on <a href="/wiki/Windows_9x">Windows 9x</a>, <code>%COMSPEC%</code> is <a href="/wiki/COMMAND.COM">COMMAND.COM</a>.</dd></dl>
<dl><dt><code>%OS%</code></dt>
<dd>The <code>%OS%</code> variable contains a symbolic name of the operating system family to distinguish between differing feature sets in <a href="/wiki/Batchjob">batchjobs</a>. It resembles an identically named environment variable <code><a href="#%OS%">%OS%</a></code> found in all DOS-related operating systems of <a href="/wiki/Digital_Research">Digital Research</a>-origin like Concurrent DOS, <a href="/wiki/Multiuser_DOS">Multiuser DOS</a>, REAL/32, <a href="/wiki/DOS_Plus">DOS Plus</a>, <a href="/wiki/DR_DOS">DR DOS</a>, Novell DOS and OpenDOS. <code>%OS%</code> always holds the string "<code>Windows_NT</code>" on the <a href="/wiki/Windows_NT_family">Windows NT family</a>.<sup><a href="#cite_note-Ten_XP-28">[26]</a></sup></dd></dl>
<dl><dt><code>%PATH%</code></dt>
<dd>This variable contains a semicolon-delimited (do not put spaces in between) list of directories in which the command interpreter will search for an executable file that matches the given command. Environment variables that represent paths may be nested within the <code>%PATH%</code> variable, but only at one level of indirection. If this sub-path environment variable itself contains an environment variable representing a path, <code>%PATH%</code> will not expand properly in the variable substitution. Equivalent to the <a href="/wiki/Unix">Unix</a> <code><a href="#$PATH">$PATH</a></code> variable.</dd></dl>
<dl><dt><code>%ProgramFiles%</code>, <code>%ProgramFiles(x86)%</code>, <code>%ProgramW6432%</code></dt>
<dd>The <code>%ProgramFiles%</code> variable points to the <i>Program Files</i> directory, which stores all the installed programs of Windows and others. The default on English-language systems is "<code>C:\Program Files</code>". In 64-bit editions of Windows (XP, 2003, Vista), there are also <code>%ProgramFiles(x86)%</code>, which defaults to "<code>C:\Program Files (x86)</code>", and <code>%ProgramW6432%</code>, which defaults to "<code>C:\Program Files</code>". The <code>%ProgramFiles%</code> itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit (this is caused by <a href="/wiki/WoW64">Windows-on-Windows 64-bit</a> redirection).</dd></dl>
<dl><dt><code>%CommonProgramFiles%</code></dt>
<dd>This variable points to the <i>Common Files</i> directory. The default is "<code>C:\Program Files\Common Files</code>" in the English version of Windows.</dd></dl>
<dl><dt><code>%OneDrive%</code></dt>
<dd>The <code>%OneDrive%</code> variable is a special system-wide environment variable found on Windows NT and its derivatives. Its value is the path of where (if installed and setup) the Onedrive directory is located. The value of <code>%OneDrive%</code> is in most cases "<code>C:\Users\{Username}\OneDrive\</code>".</dd></dl>
<dl><dt><code>%SystemDrive%</code></dt>
<dd>The <code>%SystemDrive%</code> variable is a special system-wide environment variable found on Windows NT and its derivatives. Its value is the drive upon which the system directory was placed. The value of <code>%SystemDrive%</code> is in most cases "<code>C:</code>".</dd></dl>
<dl><dt><code>%SystemRoot%</code></dt>
<dd>The <code>%SystemRoot%</code> variable is a special system-wide environment variable found on the Windows NT family of operating systems. Its value is the location of the system directory, including the drive and path. The drive is the same as <code>%SystemDrive%</code> and the default path on a clean installation depends upon the version of the operating system. By default:
<ul><li><a href="/wiki/Windows_XP">Windows XP</a> and newer versions use "<code>\WINDOWS</code>".</li>
<li><a href="/wiki/Windows_2000">Windows 2000</a>, <a href="/wiki/Windows_NT_4.0">NT 4.0</a> and <a href="/wiki/Windows_NT_3.1">NT 3.1</a> use "<code>\WINNT</code>".</li>
<li><a href="/wiki/Windows_NT_3.5">Windows NT 3.5</a> and <a href="/wiki/Windows_NT_3.51">NT 3.51</a> uses "<code>\WINNT35</code>".</li>
<li><a href="/wiki/Windows_NT_4.0_Terminal_Server">Windows NT 4.0 Terminal Server</a> uses "<code>\WTSRV</code>".</li></ul></dd></dl>
<dl><dt><code>%windir%</code></dt>
<dd>This variable points to the <i>Windows</i> directory. (On the Windows NT family of operating systems, it is identical to the <code>%SystemRoot%</code> variable). <a href="/wiki/Windows_95">Windows 95</a>–<a href="/wiki/Windows_98">98</a> and <a href="/wiki/Windows_ME">Windows ME</a> are, by default, installed in "<code>C:\Windows</code>". For other versions of Windows, see the <code>%SystemRoot%</code> entry above.</dd></dl>
<p><i>User management variables</i><sup>[<i><a href="/wiki/Wikipedia:Citation_needed">citation needed</a></i>]</sup> store information related to resources and settings owned by various <a href="/wiki/User_profile">user profiles</a> within the system. As a general rule, these variables do not refer to critical system resources or locations that are necessary for the OS to run.
</p>
<dl><dt><code>%ALLUSERSPROFILE%</code> (<code>%PROGRAMDATA%</code> since Windows Vista)</dt>
<dd>This variable expands to the full path to the <i>All Users</i> profile directory. This profile contains resources and settings that are used by all system accounts. <a href="/wiki/Shortcut_(computing)">Shortcut</a> links copied to the <i>All Users</i>\' <i>Start menu</i> or <i>Desktop</i> directories will appear in every user's <i>Start menu</i> or <i><a href="/wiki/Desktop_metaphor">Desktop</a></i>, respectively.</dd></dl>
<dl><dt><code>%USERDOMAIN%</code></dt>
<dd>The name of the <i><a href="/wiki/Workgroup_(computer_networking)">Workgroup</a></i> or <i><a href="/wiki/Windows_Server_domain">Windows Domain</a></i> to which the current user belongs. The related variable, <code>%LOGONSERVER%</code>, holds the <a href="/wiki/Hostname">hostname</a> of the server that authenticated the current user's login credentials (name and password). For home PCs and PCs in a workgroup, the authenticating server is usually the PC itself. For PCs in a Windows domain, the authenticating server is a <a href="/wiki/Domain_controller">domain controller</a> (a primary domain controller, or PDC, in Windows NT 4-based domains).</dd></dl>
<dl><dt><code>%USERPROFILE%</code></dt>
<dd>A special system-wide environment variable found on Windows NT and its derivatives. Its value is the location of the current user's profile directory, in which is found that user's HKCU registry hive (<code>NTUSER</code>). Users can also use the <code>%USERNAME%</code> variable to determine the active users login identification.</dd></dl>
<p><i>Optional System variables</i><sup>[<i><a href="/wiki/Wikipedia:Citation_needed">citation needed</a></i>]</sup> are not explicitly specified by default but can be used to modify the default behavior of certain built-in console commands. These variables also do not need to be explicitly specified as command line arguments.
</p>
<h4>Default values[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=13">edit</a>]</h4>
<p>The following tables shows typical default values of certain environment variables under English versions of Windows as they can be retrieved under <code><a href="/wiki/CMD_(Windows)">CMD</a></code>.
</p><p>(Some of these variables are also defined when running <code>COMMAND.COM</code> under Windows, but differ in certain important details: Under <code>COMMAND.COM</code>, the names of environment variable are always uppercased. Some, but not all variables contain short <a href="/wiki/8.3_filename">8.3</a> rather than <a href="/wiki/Long_file_name">long file names</a>. While some variables present in the <code>CMD</code> environment are missing, there are also some variables specific to the <code>COMMAND</code> environment.)
</p>
<table>
<tbody><tr>
<th>Variable
</th>
<th>Locale specific
</th>
<th>Windows XP (CMD)
</th>
<th>Windows Vista and later (CMD)
</th></tr>
<tr>
<td>%ALLUSERSPROFILE%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>C:\Documents and Settings\All Users
</td>
<td>C:\ProgramData<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%APPDATA%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>C:\Documents and Settings\{username}\Application Data
</td>
<td>C:\Users\{username}\AppData\Roaming<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%CommonProgramFiles%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>C:\Program Files\Common Files
</td>
<td>C:\Program Files\Common Files<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%CommonProgramFiles(x86)%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>C:\Program Files (x86)\Common Files <i>(only in 64-bit version)</i>
</td>
<td>C:\Program Files (x86)\Common Files <i>(only in 64-bit version)</i><sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%CommonProgramW6432%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>%CommonProgramW6432% <i>(not supported, not replaced by any value)</i>
</td>
<td>C:\Program Files\Common Files <i>(only in 64-bit version)</i><sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%COMPUTERNAME%
</td>
<td>No
</td>
<td>{computername}
</td>
<td>{computername}
</td></tr>
<tr>
<td>%ComSpec%
</td>
<td>No
</td>
<td>C:\Windows\System32\cmd.exe
</td>
<td>C:\Windows\System32\cmd.exe
</td></tr>
<tr>
<td>%HOMEDRIVE%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>No
</td>
<td>C:
</td>
<td>C:<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%HOMEPATH%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>\Documents and Settings\{username}
</td>
<td>\Users\{username}<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%LOCALAPPDATA%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>%LOCALAPPDATA% <i>(not supported, not replaced by any value)</i>
</td>
<td>C:\Users\{username}\AppData\Local<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%LOGONSERVER%
</td>
<td>No
</td>
<td>\\{domain_logon_server}
</td>
<td>\\{domain_logon_server}
</td></tr>
<tr>
<td>%PATH%
</td>
<td>Yes
</td>
<td>C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths}
</td>
<td>C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths}
</td></tr>
<tr>
<td>%PATHEXT%
</td>
<td>No
</td>
<td>.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.WSF;.WSH
</td>
<td>.com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc
</td></tr>
<tr>
<td>%ProgramData%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>%ProgramData% <i>(not supported, not replaced by any value)</i>
</td>
<td>%SystemDrive%\ProgramData<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%ProgramFiles%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>%SystemDrive%\Program Files
</td>
<td>%SystemDrive%\Program Files<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%ProgramFiles(x86)%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>%SystemDrive%\Program Files (x86) <i>(only in 64-bit version)</i>
</td>
<td>%SystemDrive%\Program Files (x86) <i>(only in 64-bit version)</i><sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%ProgramW6432%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>%ProgramW6432% <i>(not supported, not replaced by any value)</i>
</td>
<td>%SystemDrive%\Program Files <i>(only in 64-bit version)</i><sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%PROMPT%
</td>
<td>No
</td>
<td>Code for current command prompt format, usually $P$G
</td>
<td>Code for current command prompt format, usually $P$G
</td></tr>
<tr>
<td>%PSModulePath%
</td>
<td>
</td>
<td>%PSModulePath% <i>(not supported, not replaced by any value)</i>
</td>
<td>%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\
</td></tr>
<tr>
<td>%PUBLIC%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>%PUBLIC% <i>(not supported, not replaced by any value)</i>
</td>
<td>%SystemDrive%\Users\Public<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%SystemDrive%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>No
</td>
<td>C:
</td>
<td>C:<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%SystemRoot%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>No
</td>
<td>The Windows directory, usually C:\Windows, formerly C:\WINNT
</td>
<td>%SystemDrive%\Windows<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%TEMP%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup> and %TMP%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>%SystemDrive%\Documents and Settings\{username}\Local Settings\Temp
</td>
<td>%SystemRoot%\TEMP (for system environment variables %TMP% and %TEMP%), %USERPROFILE%\AppData\Local\Temp<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup> (for user environment variables %TMP% and %TEMP%)
</td></tr>
<tr>
<td>%USERDOMAIN%
</td>
<td>No
</td>
<td>{userdomain}
</td>
<td>{userdomain}
</td></tr>
<tr>
<td>%USERNAME%
</td>
<td>No
</td>
<td>{username}
</td>
<td>{username}
</td></tr>
<tr>
<td>%USERPROFILE%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>Yes
</td>
<td>%SystemDrive%\Documents and Settings\{username}
</td>
<td>%SystemDrive%\Users\{username}<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr>
<tr>
<td>%windir%<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td>
<td>No
</td>
<td>%SystemDrive%\WINDOWS
</td>
<td>%SystemDrive%\Windows<sup><a href="#cite_note-Schulz_2014_Ordner-29">[27]</a></sup>
</td></tr></tbody></table>
<p>In this list, there is no environment variable that refers to the location of the user's <i>My Documents</i> directory, so there is no standard method for setting a program's home directory to be the <i>My Documents</i> directory.
</p>
<h2>Pseudo-environment variables[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=14">edit</a>]</h2>
<p>The command processors in DOS and Windows also support pseudo-environment variables. These are values that are fetched like environment variables, but are not truly stored in the environment but computed when requested.
</p>
<h3>DOS[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=15">edit</a>]</h3>
<p>Besides true environment variables, which are statically stored in the environment until changed or deleted, a number of pseudo-environment variables exist for batch processing.
</p><p>The so-called <i>replacement parameters</i> or <i>replaceable parameters</i> (Microsoft / IBM terminology) aka <i>replacement variables</i> (Digital Research / Novell / Caldera terminology)<sup><a href="#cite_note-Caldera_1998_USER-23">[21]</a></sup> or <i><a href="/wiki/Batch_file_parameter">batch file parameters</a></i> (JP Software terminology)<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> <code>%1</code>..<code>%9</code> and <code>%0</code> can be used to retrieve the calling parameters of a batchjob, see <code><a href="/wiki/SHIFT_(DOS_command)">SHIFT</a></code>. In batchjobs, they can be retrieved just like environment variables, but are not actually stored in the environment.
</p><p>
Some command-line processors (like <a href="/wiki/DR-DOS">DR-DOS</a> <code>COMMAND.COM</code>,<sup><a href="#cite_note-Caldera_1998_USER-23">[21]</a></sup> <a href="/wiki/Multiuser_DOS">Multiuser DOS</a> <code>MDOS.COM</code>/<code><a href="/wiki/TMP.EXE">TMP.EXE</a></code> (Terminal Message Process), JP Software <a href="/wiki/4DOS">4DOS</a>, <a href="/wiki/4OS2">4OS2</a>, <a href="/wiki/4NT_(shell)">4NT</a>, <a href="/wiki/Take_Command_(command_line_interpreter)">Take Command</a> and Windows <a href="/wiki/Cmd.exe">cmd.exe</a>) support a type of pseudo-environment variables named <i>system information variables</i> (Novell / Caldera terminology)<sup><a href="#cite_note-Caldera_1998_USER-23">[21]</a></sup> or <i>internal variables</i> (JP Software terminology),<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> which can be used to retrieve various possibly dynamic, but read-only information about the running system in batch jobs. The returned values represent the status of the system in the moment these variables are queried; that is, reading them multiple times in a row may return different values even within the same command; querying them has no direct effect on the system. Since they are not stored in the environment, they are not listed by <a href="/wiki/SET_(DOS_command)">SET</a> and do not exist for external programs to retrieve. If a true environment variable of the same name is defined, it takes precedence over the corresponding variable until the environment variable is deleted again. They are not case-sensitive.
While almost all such variables are prefixed with an <a href="/wiki/Underscore">underscore</a> ("<code>_</code>") by 4DOS etc. by convention (f.e. <code><a href="#%_SECOND%">%_SECOND%</a></code>),<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> they are not under DR-DOS <code>COMMAND.COM</code> (f.e. <code><a href="#%OS_VERSION%">%OS_VERSION%</a></code>).
</p><p>In addition, 4DOS, 4OS2, 4NT, and Take Command also support so called <i>variable functions</i>,<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> including user-definable ones. They work just like <i>internal variables</i>, but can take optional parameters (f.e. <code>%@EVAL[]%</code>) and may even change the system status depending on their function.
</p><p><i>System information variables</i> supported by DR-DOS <code>COMMAND.COM</code>:
</p>
<dl><dt><code>%AM_PM%</code></dt>
<dd>This pseudo-variable returns the ante- or post-midday status of the current time. The returned string depends on the locale-specific version of DR-DOS, f.e. "<code>am</code>" or "<code>pm</code>" in the English version. It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts.</dd></dl>
<dl><dt><code>%DAY%</code></dt>
<dd>This pseudo-variable returns the days of the current date in a 2-digit format with leading zeros, f.e. "<code>01</code>".."<code>31</code>". See also the similar pseudo-variable <code><a href="#%_DAY%">%_DAY%</a></code>. It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts.</dd></dl>
<dl><dt><code>%DAY_OF_WEEK%</code></dt>
<dd>This pseudo-variable returns the day name of the week in a 3-character format. The returned string depends on the locale-specific version of DR-DOS, f.e. "<code>Sun</code>", "<code>Mon</code>", "<code>Tue</code>", "<code>Wed</code>", "<code>Thu</code>", "<code>Fri</code>", or "<code>Sat</code>" in the English version. It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts.</dd></dl>
<dl><dt><code>%ERRORLEVEL%</code></dt>
<dd>In <code>COMMAND.COM</code> of DR-DOS 7.02 and higher, this pseudo-variable returns the last error level returned by an external program or the <code><a href="/wiki/RETURN_(DOS_command)">RETURN</a></code> command, f.e. "<code>0</code>".."<code>255</code>".<sup><a href="#cite_note-Paul_1997_BATTIPS-30">[28]</a></sup><sup><a href="#cite_note-FD_2003_Errorlevel-31">[29]</a></sup> See also the identically named pseudo-variable <code><a href="#ERRORLEVEL">%ERRORLEVEL%</a></code> under Windows and the <code><a href="/wiki/IF_ERRORLEVEL_(DOS_command)">IF ERRORLEVEL</a></code> conditional command.</dd></dl>
<dl><dt><code>%ERRORLVL%</code></dt>
<dd>In DR-DOS 7.02 and higher, this pseudo-variable returns the last error level in a 3-digit format with leading zeros, f.e. "<code>000</code>".."<code>255</code>".<sup><a href="#cite_note-Paul_1997_BATTIPS-30">[28]</a></sup><sup><a href="#cite_note-FD_2003_Errorlevel-31">[29]</a></sup> Under <a href="/wiki/Multiuser_DOS">Multiuser DOS</a>, this is a true environment variable automatically updated by the shell to the return code of exiting programs.<sup><a href="#cite_note-CCI_1997_HELP-25">[23]</a></sup> See also the related pseudo-variable <code><a href="#%ERRORLEVEL%">%ERRORLEVEL%</a></code> under DR-DOS and the <code><a href="/wiki/IF_ERRORLEVEL_(DOS_command)">IF ERRORLEVEL</a></code> command.</dd></dl>
<dl><dt><code>%GREETING_TIME%</code></dt>
<dd>This pseudo-variable returns the 3-level day greeting time. The returned string depends on the locale-specific version of DR-DOS, f.e. "<code>morning</code>", "<code>afternoon</code>", or "<code>evening</code>" in the English version. It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts.</dd></dl>
<dl><dt><code>%HOUR%</code></dt>
<dd>This pseudo-variable returns the hours of the current time in 12-hour format without leading zeros, f.e. "<code>1</code>".."<code>12</code>". It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts.</dd></dl>
<dl><dt><code>%HOUR24%</code></dt>
<dd>This pseudo-variable returns the hours of the current time in 24-hour format in a 2-digit format with leading zeros, f.e. "<code>00</code>".."<code>23</code>". It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts. See also the similar pseudo-variable <code><a href="#%_HOUR%">%_HOUR%</a></code>.</dd></dl>
<dl><dt><code>%MINUTE%</code></dt>
<dd>This pseudo-variable returns the minutes of the current time in a 2-digit format with leading zeros, f.e "<code>00</code>".."<code>59</code>". It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts. See also the similar pseudo-variable <code><a href="#%_MINUTE%">%_MINUTE%</a></code>.</dd></dl>
<dl><dt><code>%MONTH%</code></dt>
<dd>This pseudo-variable returns the months of the current date in a 2-digit format with leading zeros, f.e. "<code>01</code>".."<code>12</code>". It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts. See also the similar pseudo-variable <code><a href="#%_MONTH%">%_MONTH%</a></code>.</dd></dl>
<dl><dt><code>%MONTH_NAME%</code></dt>
<dd>This pseudo-variable returns the month name of the current date. The returned string depends on the locale-specific version of DR-DOS, f.e. "<code>January</code>", "<code>February</code>", "<code>March</code>", "<code>April</code>", "<code>May</code>", "<code>June</code>", "<code>July</code>", "<code>August</code>", "<code>September</code>", "<code>October</code>", or "<code>December</code>" in the English version. It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts.</dd></dl>
<dl><dt><code>%NDAY_OF_WEEK%</code></dt>
<dd>This pseudo-variable returns the number of day of the current week, f.e. "<code>1</code>".."<code>7</code>" (with "<code>1</code>" for Sunday). It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts.</dd></dl>
<dl><dt><code>%OS_VERSION%</code></dt>
<dd>This pseudo-variable returns the version of the operating system depending on the current setting of the environment variable <code><a href="#%VER%">%VER%</a></code>. If <code>%VER%</code> is not defined, <code>%OS_VERSION%</code> returns "<code>off</code>". It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts, which may return versions also for non-DR-DOS versions of DOS.</dd></dl>
<dl><dt><code>%SECOND%</code></dt>
<dd>This pseudo-variable returns the seconds of the current time in a 2-digit format with leading zeros, f.e. "<code>00</code>".."<code>59</code>". It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts. See also the similar pseudo-variable <code><a href="#%_SECOND%">%_SECOND%</a></code>.</dd></dl>
<dl><dt><code>%SHORT_YEAR%</code></dt>
<dd>This pseudo-variable returns the year of the current date in a 2-digit format with leading zeros, f.e. "<code>93</code>".."<code>99</code>", "<code>00</code>".."<code>92</code>". It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts.</dd></dl>
<dl><dt><code>%YEAR%</code> and <code>%_YEAR%</code></dt>
<dd>Supported since <a href="/wiki/Novell_DOS_7">Novell DOS 7</a>, the <code>%YEAR%</code> pseudo-variable returns the year of the current date in a 4-digit format, f.e. "<code>1980</code>".."<code>2099</code>". It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts. DR-DOS 7.02 and higher added <code>%_YEAR%</code> for compatibility with <a href="/wiki/4DOS">4DOS</a>, returning the same value.<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup></dd></dl>
<dl><dt><code>%/%</code></dt>
<dd>In <code>COMMAND.COM</code> of DR-DOS 7.02 and higher, this pseudo-variable returns the current <a href="/wiki/SwitChar">SwitChar</a> setting of the system, either "<code>/</code>" (DOS style) or "<code>-</code>" (Unix style).<sup><a href="#cite_note-Caldera_1998_DELTREE101-32">[30]</a></sup><sup><a href="#cite_note-Caldera_1998_NEW703-33">[31]</a></sup> See also the related <code>CONFIG.SYS</code> directive <a href="/wiki/SWITCHAR_(CONFIG.SYS_directive)">SWITCHAR</a> and the environment variable <code><a href="#%SWITCHAR%">%SWITCHAR%</a></code>.</dd></dl>
<dl><dt><code>%_CODEPAGE%</code></dt>
<dd>This pseudo-variable returns the systems' current <a href="/wiki/Code_page">code page</a> ("<code>1</code>".."<code>65533</code>"), f.e. "<code><a href="/wiki/Codepage_437">437</a></code>", "<code><a href="/wiki/Codepage_850">850</a></code>", "<code><a href="/wiki/Codepage_858">858</a></code>". This variable was originally introduced by <a href="/wiki/4DOS">4DOS</a>,<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the <code><a href="/wiki/CHCP_(DOS_command)">CHCP</a></code> command.</dd></dl>
<dl><dt><code>%_COLUMNS%</code></dt>
<dd>This pseudo-variable returns the current number of screen columns depending on the display mode, f.e. "<code>40</code>", "<code>80</code>", "<code>132</code>", etc. This variable was originally introduced by <a href="/wiki/4DOS">4DOS</a>,<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also a similar environment variable <code><a href="#%$WIDTH%">%$WIDTH%</a></code> under DOS Plus.</dd></dl>
<dl><dt><code>%_COUNTRY%</code></dt>
<dd>This pseudo-variable returns the systems' current <a href="/wiki/List_of_country_calling_codes">country code</a> ("<code>1</code>".."<code>65534</code>"), f.e. "<code>1</code>" for USA, "<code>44</code>" for UK, "<code>49</code>" for Germany, "<code>20049</code>" with <a href="/wiki/ISO_8601">ISO 8601</a>, "<code>21049</code>" with ISO 8601 and <a href="/wiki/Euro_currency">Euro</a> support.<sup><a href="#cite_note-Caldera_1998_NEW703-33">[31]</a></sup><sup><a href="#cite_note-Paul_2001_COUNTRY-34">[32]</a></sup> This variable was originally introduced by <a href="/wiki/4DOS">4DOS</a>,<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the <code>CONFIG.SYS</code> directive <code><a href="/wiki/COUNTRY_(CONFIG.SYS_directive)">COUNTRY</a></code>.</dd></dl>
<dl><dt><code>%_DAY%</code></dt>
<dd>This pseudo-variable returns the days of the current date without leading zeros, f.e. "<code>1</code>".."<code>31</code>". This variable was originally introduced by <a href="/wiki/4DOS">4DOS</a>,<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the similar pseudo-variable <code><a href="#DAY%">%DAY%</a></code>.</dd></dl>
<dl><dt><code>%_HOUR%</code></dt>
<dd>This pseudo-variable returns the hours of the current time in 24-hour format without leading zeros, f.e. "<code>0</code>".."<code>23</code>". This variable was originally introduced by <a href="/wiki/4DOS">4DOS</a>,<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the similar pseudo-variable <code><a href="#%HOUR24%">%HOUR24%</a></code>.</dd></dl>
<dl><dt><code>%_MINUTE%</code></dt>
<dd>This pseudo-variable returns the minutes of the current time without leading zeros, f.e "<code>0</code>".."<code>59</code>". This variable was originally introduced by <a href="/wiki/4DOS">4DOS</a>,<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the similar pseudo-variable <code><a href="#%MINUTE%">%MINUTE%</a></code>.</dd></dl>
<dl><dt><code>%_MONTH%</code></dt>
<dd>This pseudo-variable returns the months of the current date without leading zeros, f.e. "<code>1</code>".."<code>12</code>". This variable was originally introduced by <a href="/wiki/4DOS">4DOS</a>,<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the similar pseudo-variable <code><a href="#%MONTH%">%MONTH%</a></code>.</dd></dl>
<dl><dt><code>%_ROWS%</code></dt>
<dd>This pseudo-variable returns the current number of screen rows depending on the display mode, f.e. "<code>25</code>", "<code>43</code>", "<code>50</code>", etc. This variable was originally introduced by <a href="/wiki/4DOS">4DOS</a>,<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See a similar environment variable <code><a href="#%$LENGTH%">%$LENGTH%</a></code> under DOS Plus.</dd></dl>
<dl><dt><code>%_SECOND%</code></dt>
<dd>This pseudo-variable returns the seconds of the current time without leading zeros, f.e. "<code>0</code>".."<code>59</code>". This variable was originally introduced by <a href="/wiki/4DOS">4DOS</a>,<sup><a href="#cite_note-4DOS_8.00_HELP-10">[10]</a></sup> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the similar pseudo-variable <code><a href="#%SECOND%">%SECOND%</a></code>.</dd></dl>
<p><i>System information variables</i> supported by DR-DOS <code>COMMAND.COM</code> with networking loaded:
</p>
<dl><dt><code>%LOGIN_NAME%</code></dt>
<dd>This pseudo-variable returns the user name. This always worked with <code><a href="/wiki/NETX">NETX</a></code>, but it will also work with <a href="/wiki/Personal_NetWare">Personal NetWare</a>'s <a href="/wiki/Open_Data-Link_Interface">ODI</a>/<a href="/wiki/Virtual_Loadable_Module">VLM</a> if the current drive is a PNW-mapped drive (otherwise an empty string is returned). See also the similarly named environment variable <code><a href="#%LOGINNAME%">%LOGINNAME%</a></code>.</dd></dl>
<dl><dt><code>%P_STATION%</code></dt>
<dd>This pseudo-variable returns the physical station number in a format "<code>????????????</code>". The value depends on the <a href="/wiki/MAC_address">MAC address</a> of the network adapter, but can be overridden. It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts.</dd></dl>
<dl><dt><code>%STATION%</code></dt>
<dd>This pseudo-variable returns the logical station number starting with "<code>1</code>" for the first client. The numbers are assigned by the file server and remain static for as long as the <a href="/wiki/IPX">IPX</a> connection remains established. It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts.</dd></dl>
<dl><dt><code>%FULL_NAME%</code></dt>
<dd>This pseudo-variable returns the full name of the logged in user, if available. It resembles an identically named <i>identifier variable</i> in <a href="/wiki/Novell_NetWare">Novell NetWare</a> login scripts. See also the related pseudo-variable <code><a href="#%LOGIN_NAME%">%LOGIN_NAME%</a></code>.</dd></dl>
<h3>Windows[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=16">edit</a>]</h3>
<p><i>Dynamic environment variables</i> (also named <i>internal variables</i> or <i>system information variables</i> under DOS) are pseudo-environment variables supported by <code><a href="/wiki/CMD_(Windows)">CMD.EXE</a></code> when command-line extensions are enabled, and they expand to various discrete values whenever queried, that is, their values can change when queried multiple times even within the same command. While they can be used in batch jobs and at the prompt, they are not stored in the environment. Consequently, they are neither listed by <code>SET</code> nor do they exist for external programs to read. They are not case-sensitive.
</p><p>Indirectly, they are also supported under Windows' <code>COMMAND.COM</code>, which has been modified to internally call <code>CMD.EXE</code> to execute the commands.
</p>
<dl><dt><code>%CD%</code></dt>
<dd>This pseudo-variable expands to the current directory equivalent to the output of the command <code><a href="/wiki/Cd_(command)">CD</a></code> when called without arguments. While a long filename can be returned under <code>CMD.EXE</code> depending on the current directory, the fact that the current directory will always be in <a href="/wiki/8.3_filename">8.3</a> format under <code>COMMAND.COM</code> will cause it to return a short filename under <code>COMMAND.COM</code>, even when <code>COMMAND</code> internally calls <code>CMD</code>.</dd></dl>
<dl><dt><code>%CMDCMDLINE%</code></dt>
<dd>This pseudo-variable expands to the original startup parameters of <code><a href="/wiki/CMD.EXE">CMD.EXE</a></code>, f.e. "<code>C:\Windows\system32\cmd.exe</code>". Under Windows' <code>COMMAND.COM</code>, this may return something like "<code>C:\Windows\system32\cmd.exe /c ...</code>" due to the fact that <code>COMMAND.COM</code> calls <code>CMD.EXE</code> internally.</dd></dl>
<dl><dt><code>%CMDEXTVERSION%</code></dt>
<dd>This pseudo-variable expands to the version of the command-line extensions of <code><a href="/wiki/CMD.EXE">CMD.EXE</a></code>, if enabled (e.g. "<code>1</code>" under <a href="/wiki/Windows_NT">Windows NT</a>, "<code>2</code>" under <a href="/wiki/Windows_2000">Windows 2000</a> and <a href="/wiki/Windows_XP">Windows XP</a>).</dd></dl>
<dl><dt><code>%DATE%</code></dt>
<dd>This pseudo-variable expands to the current date. The date is displayed according to the current user's <a href="/wiki/Calendar_date">date format</a> preferences.</dd></dl>
<dl><dt><code>%ERRORLEVEL%</code></dt>
<dd>This pseudo-variable expands to the last set error level, a value between "<code>0</code>" and "<code>255</code>" (without leading zeros).<sup><a href="#cite_note-Paul_1997_BATTIPS-30">[28]</a></sup><sup><a href="#cite_note-Allen_2005-35">[33]</a></sup><sup><a href="#cite_note-FD_2003_Errorlevel-31">[29]</a></sup> External commands and some internal commands set error levels upon execution. See also the identically named pseudo-variable <code><a href="#%ERRORLEVEL%">%ERRORLEVEL%</a></code> under DR-DOS and the <code><a href="/wiki/IF_ERRORLEVEL_(Windows_command)">IF ERRORLEVEL</a></code> command.</dd></dl>
<dl><dt><code>%HIGHESTNUMANODENUMBER%</code></dt>
<dd>This pseudo-variable returns the number of the highest <a href="/wiki/Non-uniform_memory_access">NUMA</a> node.</dd></dl>
<dl><dt><code>%RANDOM%</code></dt>
<dd>This pseudo-variable returns a random number between "<code>0</code>" and "<code>32767</code>".</dd></dl>
<dl><dt><code>%TIME%</code></dt>
<dd>This pseudo-variable returns the current time. The time is displayed according to the current user's time format preferences. If the <code>%TIME%</code> and <code><a href="#DATE">%DATE%</a></code> variables are both used, it is important to read them both in this particular order in rapid succession in order to avoid midnight-rollover problems.</dd></dl>
<h3>Other shells[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=17">edit</a>]</h3>
<p>Unix-like shells have similar dynamically generated variables, bash's <code>$RANDOM</code> being a well-known example. However, since these shells have a concept of local variables, they are described as special local variables instead.<sup><a href="#cite_note-GNU_BASH-36">[34]</a></sup>
</p>
<h2>See also[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=18">edit</a>]</h2>
<ul><li><a href="/wiki/Variable_(computer_science)">Variable (computer science)</a></li>
<li><a href="/wiki/List_of_Unix_commands">List of Unix commands</a></li>
<li><a href="/wiki/List_of_DOS_commands">List of DOS commands</a></li>
<li><a href="/wiki/Special_folder">Special folder</a></li>
<li><a href="/wiki/Modules_Environment">Modules Environment</a></li>
<li><a href="/wiki/PWB_shell">PWB shell</a></li>
<li><a href="/wiki/Windows_Registry">Windows Registry</a></li></ul>
<h2>Notes[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=19">edit</a>]</h2>
<div><ol>
<li>^ <a href="#cite_ref-NB_ENVLEN128_14-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-NB_ENVLEN128_14-1"><sup><i><b>b</b></i></sup></a> Applications not coping properly with environment variables longer than 128 characters include <a href="/wiki/CadStar_PCB">CadStar PCB</a>, Checkit, Computer Select CD-ROM, RenderMan, <a href="/wiki/VINES_Network">VINES Network</a>, <a href="/wiki/Windows_3.0">Windows 3.0</a>, and <a href="/wiki/Word_for_Windows_6.0">Word for Windows 6.0</a>.
</li>
<li><b><a href="#cite_ref-NB_CMDLINE_20-0">^</a></b> <a href="/wiki/4DOS">4DOS</a> and <a href="/wiki/MS-DOS_7.0">MS-DOS 7.0</a> set the length to 127 and insert <a href="/wiki/ASCII_13">ASCII-13</a> at this position, but <a href="/wiki/Borland">Borland</a> libraries set the length to the invalid value of 128 and do not insert an ASCII-13. For shorter command lines, 4DOS/<a href="/wiki/NDOS">NDOS</a> and <a href="/wiki/DR-DOS">DR-DOS</a> also insert an <a href="/wiki/ASCII_0">ASCII-0</a> after the ASCII-13, but not when invoked vis <a href="/wiki/INSTALL_(CONFIG.SYS_directive)">INSTALL</a> directive; MS-DOS doesn't.
</li>
</ol></div>
<h2>References[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=20">edit</a>]</h2>
<div><ol>
<li><b><a href="#cite_ref-ClassicShS_1-0">^</a></b> <cite>Robbins, Arnold; Beebe, Nelson H. F. (May 2005). Apandi, Tatiana; Randal, Allison; Witwer, Adam (eds.). <i>Classic Shell Scripting</i> (1 ed.). <a href="/wiki/O%27Reilly_Media">O'Reilly</a>. <a href="/wiki/ISBN_(identifier)">ISBN</a> <a href="/wiki/Special:BookSources/978-0-596-00595-5"><bdi>978-0-596-00595-5</bdi></a>.</cite>
</li>
<li><b><a href="#cite_ref-OG_unset_2-0">^</a></b> <cite><a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset">"unset - unset values and attributes of variables and functions – "</a>. <i>Commands &amp; Utilities Reference, <a href="/wiki/Single_UNIX_Specification">The Single UNIX Specification</a> - The Open Group Base Specifications, IEEE Std 1003.1-2008</i> (Issue 7 ed.). The <a href="/wiki/IEEE">IEEE</a> and <a href="/wiki/The_Open_Group">The Open Group</a>. 2016 [2001]. <a href="https://web.archive.org/web/20171218175244/http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html">Archived</a> from the original on 2017-12-18. Retrieved 2017-12-18.</cite>
</li>
<li><b><a href="#cite_ref-Bash_unset_3-0">^</a></b> <cite>fgrose (2015-07-31) [2011]. <a href="http://wiki.bash-hackers.org/commands/builtin/unset">"The unset builtin command"</a>. <i>Bash Hackers Wiki</i>. <a href="https://web.archive.org/web/20171218175214/http://wiki.bash-hackers.org/commands/builtin/unset">Archived</a> from the original on 2017-12-18. Retrieved 2017-12-18.</cite>
</li>
<li><b><a href="#cite_ref-appdata_4-0">^</a></b> <cite>Jacobs, Mike; Koren, Alexander; Satran, Michael (2017-11-14). <a href="https://docs.microsoft.com/en-us/windows/uwp/app-settings/store-and-retrieve-app-data">"Store and retrieve settings and other app data"</a>. <a href="/wiki/Microsoft">Microsoft</a>. <a href="https://web.archive.org/web/20171218175200/https://docs.microsoft.com/de-de/windows/uwp/design/app-settings/store-and-retrieve-app-data">Archived</a> from the original on 2017-12-18. Retrieved 2017-12-18.</cite>
</li>
<li><b><a href="#cite_ref-ESR_2002_BROWSER_5-0">^</a></b> <cite><a href="/wiki/Eric_S._Raymond">Raymond, Eric</a> (2002-08-02) [Originally published 2001]. <a href="http://www.catb.org/~esr/BROWSER/index.html">"The BROWSER project"</a>. <a href="https://web.archive.org/web/20190921223921/http://www.catb.org/~esr/BROWSER/index.html">Archived</a> from the original on 2019-09-21. Retrieved 2020-10-21.</cite>
</li>
<li><b><a href="#cite_ref-LWN_2001_BROWSER_6-0">^</a></b> <cite><a href="https://lwn.net/2001/0201/devel.php3">"LWN - Development"</a>. <i>LWN.net</i>. 2001-02-01. <a href="https://web.archive.org/web/20190208125048/https://lwn.net/2001/0201/devel.php3">Archived</a> from the original on 2019-02-08. Retrieved 2020-10-21. <q>Standardizing a BROWSER environment variable. Eric Raymond is promoting the use of a new environment variable, BROWSER, to complement the existing PAGER, MAILER, and EDITOR variables. This effort is being tested as an experiment in hacking social systems.</q></cite>
</li>
<li><b><a href="#cite_ref-PERL_ENV_BROWSER_7-0">^</a></b> <cite>Špaček, Michal (2020-01-19) [First version published 2013]. <a href="https://metacpan.org/pod/Env::Browser">"Env::Browser-0.06"</a>. <i>metacpan.org</i>. <a href="https://web.archive.org/web/20201021202950/https://metacpan.org/pod/Env::Browser">Archived</a> from the original on 2020-10-21. Retrieved 2020-10-21. <q>Env::Browser - Process environment variable $BROWSER and run web browser</q></cite>
</li>
<li><b><a href="#cite_ref-PYTHON_WEBBROWSER_8-0">^</a></b> <cite><a href="https://docs.python.org/3/library/webbrowser.html">"webbrowser — Convenient Web-browser controller"</a>. <i>docs.python.org</i>. <a href="https://web.archive.org/web/20201013205951/https://docs.python.org/3/library/webbrowser.html">Archived</a> from the original on 2020-10-13. Retrieved 2020-10-21.</cite>
</li>
<li><b><a href="#cite_ref-DEBIAN_DFLT_WEB_BROWSER_9-0">^</a></b> <cite><a href="https://wiki.debian.org/DefaultWebBrowser">"DefaultWebBrowser - Debian Wiki"</a>. <i>wiki.debian.org</i>. 2020-06-10. <a href="https://web.archive.org/web/20201021204658/https://wiki.debian.org/DefaultWebBrowser">Archived</a> from the original on 2020-10-21. Retrieved 2020-10-21. <q>The environment variable BROWSER can be set to[…] always choose your desired browser.</q></cite>
</li>
<li>^ <a href="#cite_ref-4DOS_8.00_HELP_10-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-7"><sup><i><b>h</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-8"><sup><i><b>i</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-9"><sup><i><b>j</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-10"><sup><i><b>k</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-11"><sup><i><b>l</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-12"><sup><i><b>m</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-13"><sup><i><b>n</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-14"><sup><i><b>o</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-15"><sup><i><b>p</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-16"><sup><i><b>q</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-17"><sup><i><b>r</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-18"><sup><i><b>s</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-19"><sup><i><b>t</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-20"><sup><i><b>u</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-21"><sup><i><b>v</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-22"><sup><i><b>w</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-23"><sup><i><b>x</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-24"><sup><i><b>y</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-25"><sup><i><b>z</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-26"><sup><i><b>aa</b></i></sup></a> <a href="#cite_ref-4DOS_8.00_HELP_10-27"><sup><i><b>ab</b></i></sup></a> <cite>Brothers, Hardin; <a href="/wiki/Tom_Rawson">Rawson, Tom</a>; <a href="/wiki/Rex_C._Conn">Conn, Rex C.</a>; Paul, Matthias R.; Dye, Charles E.; Georgiev, Luchezar I. (2002-02-27). <a href="/wiki/4DOS_8.00"><i>4DOS 8.00 online help</i></a>.</cite>
</li>
<li>^ <a href="#cite_ref-Paul_1997_NWDOSTIP_11-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-7"><sup><i><b>h</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-8"><sup><i><b>i</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-9"><sup><i><b>j</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-10"><sup><i><b>k</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-11"><sup><i><b>l</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-12"><sup><i><b>m</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-13"><sup><i><b>n</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-14"><sup><i><b>o</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-15"><sup><i><b>p</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-16"><sup><i><b>q</b></i></sup></a> <a href="#cite_ref-Paul_1997_NWDOSTIP_11-17"><sup><i><b>r</b></i></sup></a> <cite>Paul, Matthias R. (1997-07-30) [1994-05-01]. <a href="http://www.antonis.de/dos/dos-tuts/mpdostip/html/nwdostip.htm"><i>NWDOS-TIPs — Tips &amp; Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds</i></a>. <i>MPDOSTIP</i>. Release 157 (in German) (3 ed.). <a href="https://web.archive.org/web/20161104235829/http://www.antonis.de/dos/dos-tuts/mpdostip/html/nwdostip.htm">Archived</a> from the original on 2016-11-04. Retrieved 2014-08-06.</cite> (NB. NWDOSTIP.TXT is a comprehensive work on <a href="/wiki/Novell_DOS_7">Novell DOS 7</a> and <a href="/wiki/OpenDOS_7.01">OpenDOS 7.01</a>, including the description of many undocumented features and internals. The provided link points to a HTML-converted version of the file, which is part of the <code>MPDOSTIP.ZIP</code> collection.) <a href="https://web.archive.org/web/20190601152204/https://www.sac.sk/download/text/mpdostip.zip">[1]</a>
</li>
<li>^ <a href="#cite_ref-Paul_1997_4DOSTIP_12-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Paul_1997_4DOSTIP_12-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Paul_1997_4DOSTIP_12-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-Paul_1997_4DOSTIP_12-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-Paul_1997_4DOSTIP_12-4"><sup><i><b>e</b></i></sup></a> <cite>Paul, Matthias R. (1997-05-01) [1995-03-01]. <a href="http://www.antonis.de/dos/dos-tuts/mpdostip/html/4dostip.htm">"Hinweise zu JPSofts 4DOS 5.5b/c, 5.51, 5.52a und NDOS"</a>. <i>MPDOSTIP</i> (in German). <a href="https://web.archive.org/web/20161104211143/http://www.antonis.de/dos/dos-tuts/mpdostip/html/4dostip.htm">Archived</a> from the original on 2016-11-04. Retrieved 2015-05-08.</cite> (NB. The provided link points to a HTML-converted version of the <code>4DOS5TIP.TXT</code> file, which is part of the <code>MPDOSTIP.ZIP</code> collection.) <a href="https://web.archive.org/web/20190601152204/https://www.sac.sk/download/text/mpdostip.zip">[2]</a>
</li>
<li>^ <a href="#cite_ref-Paul_1997_OD-A3_13-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Paul_1997_OD-A3_13-1"><sup><i><b>b</b></i></sup></a> <cite>Paul, Matthias R. (1997-10-02). <a href="https://web.archive.org/web/20031004074600/http://www-student.informatik.uni-bonn.de/~frinke/ibmbioa3.zip">"Caldera OpenDOS 7.01/7.02 Update Alpha 3 IBMBIO.COM README.TXT"</a>. Archived from <a href="http://www.uni-bonn.de/~uzs180/download/ibmbioa3.zip">the original</a> on 2003-10-04. Retrieved 2009-03-29.</cite> <a href="https://web.archive.org/web/20181225154705/http://mirror.macintosharchive.org/max1zzz.co.uk/+Windows%20&amp;%20DOS/DOS/System/Novell/Support/Bins/Op702src.zip">[3]</a>
</li>
<li><b><a href="#cite_ref-Paul_1997_SETENV_15-0">^</a></b> <cite>Paul, Matthias R. (1997-05-27) [1996]. <a href="https://web.archive.org/web/20090215001349/http://www.uni-bonn.de/~uzs180/mpdokeng.html#M.SETENV">"SETENV v1.11"</a>. Archived from <a href="http://www.uni-bonn.de/~uzs180/mpdokeng.html#M.SETENV">the original</a> on 2009-02-15. Retrieved 2019-08-09. <q>[…] SETENV […] to hide and later restore the […] pre-environment […] By using SETENV.COM you can save some KiloBytes of rare DOS memory […] depending on the number of drivers loaded by <a href="/wiki/INSTALL_(CONFIG.SYS_directive)">INSTALL=</a>/<a href="/wiki/INSTALLHIGH_(CONFIG.SYS_directive)">INSTALLHIGH=</a>/<a href="/wiki/HIINSTALL_(CONFIG.SYS_directive)">HIINSTALL=</a> and the current size of the pre-environment. […] this original […] feature cannot be found in any known memory manager/optimizer. […]</q></cite>
</li>
<li><b><a href="#cite_ref-Paul_2002_CTMOUSE_16-0">^</a></b> <cite>Paul, Matthias R. (2002-04-06). <a href="https://marc.info/?l=freedos-dev&amp;m=101807226917577">"Re: [fd-dev] ANNOUNCE: CuteMouse 2.0 alpha 1"</a>. <i>freedos-dev</i>. <a href="https://web.archive.org/web/20200207130948/https://marc.info/?l=freedos-dev&amp;m=101807226917577&amp;w=2">Archived</a> from the original on 2020-02-07. Retrieved 2020-02-07. <q>[…] In CTMOUSE.ASM prepareTSR routine I found a comment in regard to the zero-environment. […] <a href="/wiki/DESQview">DESQview</a> or <a href="/wiki/DR-DOS">DRDOS</a> zero-env? […] release environment block […] skip if any problem […] zero-pad for <a href="/wiki/MEM_(DOS_command)">MEM</a> style utilities […]</q></cite>
</li>
<li><b><a href="#cite_ref-PTS-DOS_2000_17-0">^</a></b> <cite><a href="http://download.paragon-software.com/doc/manual_dos_eng.pdf">"PTS-DOS 2000 Pro User Manual"</a> (PDF). <a href="https://web.archive.org/web/20180512094512/http://download.paragon-software.com/doc/manual_dos_eng.pdf">Archived</a> (PDF) from the original on 2018-05-12. Retrieved 2018-05-12.</cite>
</li>
<li><b><a href="#cite_ref-Paul_2002_COM_18-0">^</a></b> <cite>Paul, Matthias R. (2002-10-07). <a href="https://groups.google.com/d/msg/alt.msdos.programmer/d7blJjY0H5M/Qu3VeTOIGVcJ">"Re: Run a COM file"</a>. <a href="/wiki/Usenet_newsgroup">Newsgroup</a>: <a>alt.msdos.programmer</a>. <a href="https://archive.today/20170903230312/https://groups.google.com/forum/%23!msg/alt.msdos.programmer/d7blJjY0H5M/Qu3VeTOIGVcJ">Archived</a> from the original on 2017-09-03. Retrieved 2017-09-03.</cite> <a href="https://groups.google.com/d/msg/alt.lang.asm/PNOd9zfYow0/vXbab16j4XwJ">[4]</a>
</li>
<li>^ <a href="#cite_ref-Datalight_2005_ROM-DOS_19-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Datalight_2005_ROM-DOS_19-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Datalight_2005_ROM-DOS_19-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-Datalight_2005_ROM-DOS_19-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-Datalight_2005_ROM-DOS_19-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-Datalight_2005_ROM-DOS_19-5"><sup><i><b>f</b></i></sup></a> <cite><a href="/wiki/Datalight,_Inc.">Datalight, Inc.</a>; GPvNO (April 2005) [1999]. <a href="https://www.datalight.com/assets/files/ROM-DOS_Users_Guide.pdf">"Datalight ROM-DOS User's Guide"</a> (PDF). <a href="/wiki/Datalight,_Inc.">Datalight, Inc.</a> 3010-0200-0716. <a href="https://web.archive.org/web/20190320151321/https://www.datalight.com/assets/files/ROM-DOS_Users_Guide.pdf">Archived</a> (PDF) from the original on 2019-03-20. Retrieved 2018-09-16.</cite>
</li>
<li>^ <a href="#cite_ref-Kotulla_1987_Environment_21-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Kotulla_1987_Environment_21-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Kotulla_1987_Environment_21-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-Kotulla_1987_Environment_21-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-Kotulla_1987_Environment_21-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-Kotulla_1987_Environment_21-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-Kotulla_1987_Environment_21-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-Kotulla_1987_Environment_21-7"><sup><i><b>h</b></i></sup></a> <a href="#cite_ref-Kotulla_1987_Environment_21-8"><sup><i><b>i</b></i></sup></a> <cite><a href="/wiki/Martin_Kotulla">Kotulla, Martin</a> (November 1987). <a href="http://www.homecomputerworld.at/magazine/cpc/CPCAI-87-11.pdf">"Von CP/M zu MS-DOS, Teil 11"</a> (PDF). <i>Professional Computing (PC) - Schneider International</i> (in German). <b>3</b> (11): 100–103. <a href="https://web.archive.org/web/20190424201007/http://www.homecomputerworld.at/magazine/cpc/CPCAI-87-11.pdf">Archived</a> (PDF) from the original on 2019-04-24. Retrieved 2018-05-20.</cite>
</li>
<li>^ <a href="#cite_ref-Paul_2002_CLS_22-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-7"><sup><i><b>h</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-8"><sup><i><b>i</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-9"><sup><i><b>j</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-10"><sup><i><b>k</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-11"><sup><i><b>l</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-12"><sup><i><b>m</b></i></sup></a> <a href="#cite_ref-Paul_2002_CLS_22-13"><sup><i><b>n</b></i></sup></a> <cite>Paul, Matthias R. (2002-03-26). <a href="https://marc.info/?l=freedos-dev&amp;m=101717593306186&amp;w=2">"Updated CLS posted"</a>. freedos-dev mailing list. <a href="https://web.archive.org/web/20181004145539/https://marc.info/?l=freedos-dev&amp;m=101717593306186&amp;w=2">Archived</a> from the original on 2018-10-04. Retrieved 2014-08-06.</cite>
</li>
<li>^ <a href="#cite_ref-Caldera_1998_USER_23-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Caldera_1998_USER_23-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Caldera_1998_USER_23-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-Caldera_1998_USER_23-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-Caldera_1998_USER_23-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-Caldera_1998_USER_23-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-Caldera_1998_USER_23-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-Caldera_1998_USER_23-7"><sup><i><b>h</b></i></sup></a> <cite><a href="https://web.archive.org/web/20161104235434/http://www.drdos.net/documentation/usergeng/uglontoc.htm"><i>Caldera DR-DOS 7.02 User Guide</i></a>. <a href="/wiki/Caldera,_Inc.">Caldera, Inc.</a> 1998 [1993, 1997]. Archived from <a href="http://www.drdos.net/documentation/usergeng/uglontoc.htm">the original</a> on 2016-11-04. Retrieved 2013-08-10.</cite>
</li>
<li>^ <a href="#cite_ref-Paul_2017_24-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Paul_2017_24-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Paul_2017_24-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-Paul_2017_24-3"><sup><i><b>d</b></i></sup></a> <cite>Paul, Matthias R. (2017-08-14) [2017-08-07]. <a href="http://hpmuseum.org/forum/thread-8774-post-77196.html#pid77196">"The continuing saga of Windows 3.1 in enhanced mode on OmniBook 300"</a>. <i>MoHPC - the Museum of HP Calculators</i>. <a href="https://web.archive.org/web/20180501185933/http://hpmuseum.org/forum/thread-8774-post-77196.html">Archived</a> from the original on 2018-05-01. Retrieved 2018-05-01. <q>[…] set DRSYS=ON (optional to tell SYS you are aware of the fact that you're running it in a foreign environment and want to proceed anyway without having to individually ACK some warnings and extra info screens displayed in this scenario otherwise) […]</q></cite>
</li>
<li>^ <a href="#cite_ref-CCI_1997_HELP_25-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-CCI_1997_HELP_25-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-CCI_1997_HELP_25-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-CCI_1997_HELP_25-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-CCI_1997_HELP_25-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-CCI_1997_HELP_25-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-CCI_1997_HELP_25-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-CCI_1997_HELP_25-7"><sup><i><b>h</b></i></sup></a> <a href="#cite_ref-CCI_1997_HELP_25-8"><sup><i><b>i</b></i></sup></a> <cite><i>CCI Multiuser DOS 7.22 GOLD Online Documentation</i>. <a href="/wiki/Concurrent_Controls,_Inc.">Concurrent Controls, Inc.</a> (CCI). 1997-02-10. HELP.HLP.</cite>
</li>
<li><b><a href="#cite_ref-CCI_1997_PRINTDOC_26-0">^</a></b> <cite><i>CCI Multiuser DOS 7.22 GOLD Installation Guide</i>. <a href="/wiki/Concurrent_Controls,_Inc.">Concurrent Controls, Inc.</a> (CCI). 1997-02-10. PRINTDOC.HLP.</cite>
</li>
<li>^ <a href="#cite_ref-Paul_2002_OS_27-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Paul_2002_OS_27-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Paul_2002_OS_27-2"><sup><i><b>c</b></i></sup></a> <cite>Paul, Matthias R. (2002-02-20). <a href="https://marc.info/?l=freedos-dev&amp;m=101423986407077&amp;w=2">"How to detect FreeCOM/FreeDOS in-batch?"</a>. freedos-dev mailing list. <a href="https://web.archive.org/web/20181106220459/https://marc.info/?l=freedos-dev&amp;m=101423986407077&amp;w=2">Archived</a> from the original on 2018-11-06. Retrieved 2014-08-06.</cite>
</li>
<li><b><a href="#cite_ref-Ten_XP_28-0">^</a></b> <cite>Brink, Shawn (2018-11-17). <a href="https://www.tenforums.com/tutorials/3234-environment-variables-windows-10-a.html">"Environment Variables in Windows 10 - Complete List of Environment Variables in Windows 10"</a>. <i>Windows Ten Forums</i>. <a href="https://web.archive.org/web/20190327135346/https://www.tenforums.com/tutorials/3234-environment-variables-windows-10-a.html">Archived</a> from the original on 2019-03-27. Retrieved 2019-04-24.</cite>
</li>
<li>^ <a href="#cite_ref-Schulz_2014_Ordner_29-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-7"><sup><i><b>h</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-8"><sup><i><b>i</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-9"><sup><i><b>j</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-10"><sup><i><b>k</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-11"><sup><i><b>l</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-12"><sup><i><b>m</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-13"><sup><i><b>n</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-14"><sup><i><b>o</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-15"><sup><i><b>p</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-16"><sup><i><b>q</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-17"><sup><i><b>r</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-18"><sup><i><b>s</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-19"><sup><i><b>t</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-20"><sup><i><b>u</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-21"><sup><i><b>v</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-22"><sup><i><b>w</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-23"><sup><i><b>x</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-24"><sup><i><b>y</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-25"><sup><i><b>z</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-26"><sup><i><b>aa</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-27"><sup><i><b>ab</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-28"><sup><i><b>ac</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-29"><sup><i><b>ad</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-30"><sup><i><b>ae</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-31"><sup><i><b>af</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-32"><sup><i><b>ag</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-33"><sup><i><b>ah</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-34"><sup><i><b>ai</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-35"><sup><i><b>aj</b></i></sup></a> <a href="#cite_ref-Schulz_2014_Ordner_29-36"><sup><i><b>ak</b></i></sup></a> <cite>Schulz, Hajo (2014-10-02). <a href="https://www.heise.de/ct/ausgabe/2014-22-Die-benannten-Ordner-in-Windows-aus-User-und-Entwicklersicht-2406251.html">"Ordner für spezielle Fälle — Die "benannten Ordner" in Windows aus User- und Entwicklersicht"</a> [Special purpose folders — Windows' "named folders" from a user's and developer's perspective]. <i><a href="/wiki/C%27t">c't - magazin für computertechnik</a></i> (in German). <a href="/wiki/Heise_Verlag">Heise Verlag</a>. <b>2014</b> (22): 180–184. <a href="https://web.archive.org/web/20160709114401/https://www.heise.de/ct/ausgabe/2014-22-Die-benannten-Ordner-in-Windows-aus-User-und-Entwicklersicht-2406251.html">Archived</a> from the original on 2016-07-09. Retrieved 2019-04-08.</cite>
</li>
<li>^ <a href="#cite_ref-Paul_1997_BATTIPS_30-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Paul_1997_BATTIPS_30-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Paul_1997_BATTIPS_30-2"><sup><i><b>c</b></i></sup></a> <cite>Paul, Matthias R. (1997-05-01) [1993-10-01]. <a href="http://www.antonis.de/dos/batchtut/battips/index.htm#7"><i>BATTIPs — Tips &amp; Tricks zur Programmierung von Batchjobs</i></a>. <i>MPDOSTIP</i> (in German). 7: ERRORLEVEL abfragen. <a href="https://web.archive.org/web/20170823191411/http://www.antonis.de/dos/batchtut/battips/index.htm">Archived</a> from the original on 2017-08-23. Retrieved 2017-08-23.</cite> <a href="https://www.auersoft.eu/soft/by-others/dos-exitcodes-de.html">[5]</a> <a href="https://www.auersoft.eu/soft/by-others/dos-exitcodes-en.html">[6]</a> (NB. BATTIPS.TXT is part of MPDOSTIP.ZIP. The provided link points to a HTML-converted older version of the BATTIPS.TXT file.) <a href="https://web.archive.org/web/20190601152204/https://www.sac.sk/download/text/mpdostip.zip">[7]</a>
</li>
<li>^ <a href="#cite_ref-FD_2003_Errorlevel_31-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FD_2003_Errorlevel_31-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FD_2003_Errorlevel_31-2"><sup><i><b>c</b></i></sup></a> <cite>Auer, Eric; Paul, Matthias R.; <a href="/wiki/Jim_Hall_(programmer)">Hall, Jim</a> (2015-12-24) [2003-12-31]. <a href="https://web.archive.org/web/20151224202118/http://www.freedos.org/technotes/technote/207.html">"MS-DOS errorlevels"</a>. Archived from <a href="http://www.freedos.org/technotes/technote/207.html">the original</a> on 2015-12-24.</cite>
</li>
<li><b><a href="#cite_ref-Caldera_1998_DELTREE101_32-0">^</a></b> <cite>Paul, Matthias R. (1998-01-09). <a href="https://web.archive.org/web/20190408145354/http://www.lookas.net/ftp/incoming/darbui/Justas/DRDOS/DELTREE.BAT"><i>DELTREE.BAT R1.01 Extended file and directory delete</i></a>. <a href="/wiki/Caldera,_Inc.">Caldera, Inc.</a> Archived from <a href="http://www.lookas.net/ftp/incoming/darbui/Justas/DRDOS/DELTREE.BAT">the original</a> on 2019-04-08. Retrieved 2019-04-08.</cite>
</li>
<li>^ <a href="#cite_ref-Caldera_1998_NEW703_33-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Caldera_1998_NEW703_33-1"><sup><i><b>b</b></i></sup></a> <cite><a href="https://web.archive.org/web/20190408142232/http://www.lookas.net/ftp/incoming/darbui/Justas/DRDOS/WHATSNEW.TXT"><i>DR-DOS 7.03 WHATSNEW.TXT — Changes from DR-DOS 7.02 to DR-DOS 7.03</i></a>. <a href="/wiki/Caldera,_Inc.">Caldera, Inc.</a> 1998-12-24. Archived from <a href="http://www.lookas.net/ftp/incoming/darbui/Justas/DRDOS/WHATSNEW.TXT">the original</a> on 2019-04-08. Retrieved 2019-04-08.</cite>
</li>
<li><b><a href="#cite_ref-Paul_2001_COUNTRY_34-0">^</a></b> <cite>Paul, Matthias R. (2001-06-10) [1995]. <a href="http://www.columbia.edu/~em36/wpdos/MatthiasPaulCPI.zip">"DOS COUNTRY.SYS file format"</a> (COUNTRY.LST file) (1.44 ed.). <a href="https://web.archive.org/web/20160420065252/http://www.columbia.edu/~em36/wpdos/MatthiasPaulCPI.zip">Archived</a> from the original on 2016-04-20. Retrieved 2016-08-20.</cite>
</li>
<li><b><a href="#cite_ref-Allen_2005_35-0">^</a></b> <cite>Allen, William; Allen, Linda. <a href="https://web.archive.org/web/20110707113138/http://www.allenware.com/mcsw/errorlevels.zip">"Windows 95/98/ME ERRORLEVELs"</a>. Archived from <a href="http://www.allenware.com/mcsw/errorlevels.zip">the original</a> on 2011-07-07.</cite>
</li>
<li><b><a href="#cite_ref-GNU_BASH_36-0">^</a></b> <cite><a href="https://www.gnu.org/software/bash/manual/bash.html#Shell-Variables">"Shell Variables"</a>. <i>Bash Reference Manual</i>.</cite>
</li>
</ol></div>
<h2>Further reading[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=21">edit</a>]</h2>
<ul><li><cite><a href="/wiki/Raymond_Chen_(Microsoft)">Chen, Raymond</a> (2010-05-06). <a href="https://blogs.msdn.microsoft.com/oldnewthing/20100506-00/?p=14133/">"What are these strange =C: environment variables?"</a>. <i>The New Old Thing</i>. <a href="/wiki/Microsoft">Microsoft</a>. <a href="https://web.archive.org/web/20180527163745/https://blogs.msdn.microsoft.com/oldnewthing/20100506-00/?p=14133%2F">Archived</a> from the original on 2018-05-27. Retrieved 2017-05-27.</cite></li></ul>
<h2>External links[<a href="/w/index.php?title=Environment_variable&amp;action=edit&amp;section=22">edit</a>]</h2>
<ul><li><code><a href="https://man7.org/linux/man-pages/man7/environ.7.html">environ(7)</a></code>: user environment – <a href="/wiki/Linux">Linux</a> Programmer's <a href="/wiki/Man_page">Manual</a> – Overview, Conventions and Miscellanea</li>
<li><code><a href="//www.freebsd.org/cgi/man.cgi?query=environ&amp;sektion=7">environ(7)</a></code> – <a href="/wiki/FreeBSD">FreeBSD</a> Miscellaneous Information <a href="/wiki/Man_page">Manual</a></li>
<li><code><a href="https://www.unix.com/man-page/mojave/7/environ">environ(7)</a></code> – <a href="/wiki/Darwin_(operating_system)">Darwin</a> and <a href="/wiki/MacOS">macOS</a> Miscellaneous Information <a href="/wiki/Man_page">Manual</a></li>
<li><code><a href="//docs.oracle.com/cd/E26505_01/html/816-5175/environ-5.html">environ(5)</a></code> – <a href="/wiki/Solaris_(operating_system)">Solaris 10</a> Standards, Environments and Macros Reference <a href="/wiki/Man_page">Manual</a></li>
<li><cite><a href="https://web.archive.org/web/20190427235415/http://environmentvariables.org/">"Environment Variables Wiki"</a>. Archived from <a href="http://environmentvariables.org/">the original</a> on 2019-04-27.</cite></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb776899%28v=vs.85%29.aspx">User Environment Variables</a></li>
<li><a href="https://web.archive.org/web/20180511150138/https://www.setx.cc/">fix setx.exe not found bug</a></li></ul>
</div>||||I|||| Jump to content
 Toggle sidebar
 Search
 * Create account
 Personal tools
 * Create account
 * Log in

 Pages for logged out editors learn more

 * Talk
 * Contributions
 Navigation
 * Main page
 * Contents
 * Current events
 * Random article
 * About Wikipedia
 * Contact us
 * Donate
 Contribute
 * Help
 * Learn to edit
 * Community portal
 * Recent changes
 * Upload file
 Tools
 * What links here
 * Related changes
 * Upload file
 * Special pages
 * Permanent link
 * Page information
 * Cite this page
 * Wikidata item
 Print/export
 * Download as PDF
 * Printable version
 Languages
 On this Wikipedia the language links are at the top of the page across from the article title. Go to top.

 Contents

 move to sidebar hide
 * (Top)
 * 1 Design
 * 2 Syntax
 + 2.1 Unix
 + 2.2 DOS, OS/2 and Windows
 + 2.3 Assignment: Unix
 + 2.4 Assignment: DOS, OS/2 and Windows
 * 3 Examples
 * 4 True environment variables
 + 4.1 Unix
 + 4.2 DOS
 + 4.3 OS/2
 + 4.4 Windows
 o 4.4.1 Default values
 * 5 Pseudo-environment variables
 + 5.1 DOS
 + 5.2 Windows
 + 5.3 Other shells
 * 6 See also
 * 7 Notes
 * 8 References
 * 9 Further reading
 * 10 External links
 Toggle the table of contents

 Environment variable

 21 languages
 * Български
 * Català
 * Čeština
 * Deutsch
 * Español
 * فارسی
 * Français
 * 한국어
 * Italiano
 * עברית
 * Magyar
 * 日本語
 * Polski
 * Português
 * Русский
 * Suomi
 * தமிழ்
 * Türkçe
 * Українська
 * Tiếng Việt
 * 中文
 Edit links
 * Article
 * Talk
 English
 * Read
 * Edit
 * View history
 More
 * Read
 * Edit
 * View history
 From Wikipedia, the free encyclopedia

 An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.

 They were introduced in their modern form in 1979 with Version 7 Unix, so are included in all Unix operating system flavors and variants from that point onward including Linux and macOS. From PC DOS 2.0 in 1982, all succeeding Microsoft operating systems, including Microsoft Windows, and OS/2 also have included them as a feature, although with somewhat different syntax, usage and standard variable names.

 Design [ edit ]

 In all Unix and Unix-like systems, as well as on Windows, each process has its own separate set of environment variables. By default, when a process is created, it inherits a duplicate run-time environment of its parent process, except for explicit changes made by the parent when it creates the child. At the API level, these changes must be done between running 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 via env or using the ENVIRONMENT_VARIABLE=VALUE <command> notation. A running program can access the values of environment variables for configuration purposes.

 Shell scripts and batch files use environment variables to communicate data and preferences to child processes. They can also be used to store temporary values for reference later in a shell script. However, in Unix, non-exported variables are preferred for this as they don't leak outside the process.

 In Unix, an environment variable that is changed in a script or compiled program will only affect that process and possibly child processes. The parent process and any unrelated processes will not be affected. Similarly, changing or removing a variable's value inside a DOS or Windows batch file will change the variable for the duration of COMMAND.COMor CMD.EXE's existence, respectively.

 In Unix, the environment variables are normally initialized during system startup by the system init startup scripts, and hence inherited by all other processes in the system. Users can, and often do, augment them in the profile script for the command shell they are using. In Microsoft Windows, each environment variable's default value is stored in the Windows Registry or set in the AUTOEXEC.BAT file.

 On Unix, a setuid program is given an environment chosen by its caller, but it runs with different authority from its caller. The dynamic linker will usually load code from locations specified by the environment variables $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.

 In general, the collection of environment variables function as an associative array where both the keys and values are strings. The interpretation of characters in either string differs among systems. When data structures such as lists need to be represented, it is common to use a colon (common on Unix and Unix-like) or semicolon-deliminated (common on Windows and DOS) list.

 Syntax [ edit ]

 The variables can be used both in scripts and on the command line. They are usually referenced by putting special symbols in front of or around the variable name.

 It is conventional for environment variable names to be chosen to be in all upper case. In programming code generally, this helps to distinguish environment variables from other kinds of names in the code. On Unix-like operating systems, environment variable names are case sensitive, but they are not on DOS, OS/2, and Windows.

 Unix [ edit ]

 In most Unix and Unix-like command-line shells, an environment variable's value is retrieved by placing a $ sign before the variable's name. If necessary, the name can also be surrounded by braces.

 To display the user home directory, the user may type:

 echo $HOME
 

 If xyz needed to be appended to the value of the HOME variable, one might type:

 echo ${HOME}xyz
 

 In Unix and Unix-like systems, the names of environment variables are case-sensitive.

 The command env displays all environment variables and their values. The command printenv can also be used to print a single variable by giving that variable name as the sole argument to the command.

 DOS, OS/2 and Windows [ edit ]

 In DOS, OS/2 and Windows command-line interpreters such as COMMAND.COM and CMD.EXE, an environment variable is retrieved by placing a % sign before and after it.

 In DOS, OS/2 and Windows command-line interpreters as well as their API, upper or lower case is not distinguished for environment variable names.

 The environment variable named HOMEDRIVE contains the drive letter (plus its trailing : colon) of the user's home directory, whilst HOMEPATH contains the full path of the user's home directory within that drive.

 So to see the home drive and path, the user may type this:

 ECHO %HOMEDRIVE%%HOMEPATH%
 

 The command SET (with no arguments) displays all environment variables and their values. set can also be used to print all variables whose name begins with a given prefix by giving the prefix as the sole argument to the command.

 In Windows PowerShell, the user may type any of the following:

 echo $env:homedrive$env:homepath
 Write-Output $env:homedrive$env:homepath
 "$env:homedrive$env:homepath"
 

 In PowerShell, upper or lower case is not distinguished for environment variable names.

 The following command displays all environment variables and their values:

 get-childitem env:
 

 Assignment: Unix [ edit ]

 The commands env and set can be used to set environment variables and are often incorporated directly into the shell.

 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
 

 A few simple principles govern how environment variables achieve their effect.

 Environment variables are local to the process in which they were set. If two shell processes are spawned and the value of an environment variable is changed in one, that change will not be seen by the other.

 When a child process is created, it inherits all the environment variables and their values from the parent process. Usually, when a program calls another program, it first creates a child process by forking, then the child adjusts the environment as needed and lastly the child replaces itself with the program to be called. This procedure gives the calling program control over the environment of the called program.

 In Unix shells, variables may be assigned without the export keyword. Variables defined in this way are displayed by the set command, but are not true environment variables, as they are stored only by the shell and are unknown to all other processes. The printenv command will not display them, and child processes do not inherit them.

 VARIABLE=value
 

 The prefix syntax exports a "true" environment variable to a child process without affecting the current process:[1]

 VARIABLE=value program_name [arguments]
 

 The persistence of an environment variable can be session-wide or system-wide.

 unset is a builtin command implemented by both the Bourne shell family (sh, ksh, bash, etc.) and the C shell family (csh, tcsh, etc.) of Unix command line shells. It unsets a shell variable, removing it from memory and the shell's exported environment. It is implemented as a shell builtin, because it directly manipulates the internals of the shell.[2][3] Read-only shell variables cannot be unset. If one tries to unset a read-only variable, the unset command will print an error message and return a non-zero exit code.

 Assignment: DOS, OS/2 and Windows [ edit ]

 In DOS, OS/2 and Windows command-line interpreters such as COMMAND.COM and CMD.EXE, the SET command is used to assign environment variables and values using the following arguments:

 SET VARIABLE=value
 

 An environment variable is removed via:

 SET VARIABLE=
 

 The SET command without any arguments displays all environment variables along with their values; SET "0 or more spaces" shows the internal ones too. In CMD.EXE, it is possible to assign local variables that do not leak outside using the SETLOCAL command.

 In PowerShell, the assignment follows a syntax similar to Unix:

 $env:VARIABLE = "VALUE"
 

 Examples [ edit ]

 Examples of environment variables include:

 * 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 (for roaming application settings shared across multiple devices), LOCALAPPDATA (for local application settings) or PROGRAMDATA (for application settings shared between multiple OS users) should be used.[4]
 * 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 shell and variants.
 * MAIL (Unix-like): used to indicate where a user's mail is to be found.
 * TEMP: location where processes can store temporary files.

 True environment variables [ edit ]

 Unix [ edit ]

 See also: Path (computing)
 $PATH Contains a colon-separated list of directories that the shell searches for commands that do not contain a slash in their name (commands with slashes are interpreted as file names to execute, and the shell attempts to execute the files directly). It is equivalent to the DOS, OS/2 and Windows %PATH% variable. $HOME Contains the location of the user's home directory. Although the current user's home directory can also be found out through the C-functions getpwuid and getuid, $HOME is often used for convenience in various shell scripts (and other contexts). Using the environment variable also gives the user the possibility to point to another directory. $PWD This variable points to the current directory. Equivalent to the output of the command pwd when called without arguments. $DISPLAY Contains the identifier for the display that X11 programs should use by default. $LD_LIBRARY_PATH On many Unix systems with a dynamic linker, contains a colon-separated list of directories that the dynamic linker should search for shared objects when building a process image after exec, before searching in any other directories. $LIBPATH or $SHLIB_PATH Alternatives to $LD_LIBRARY_PATH typically used on older Unix versions. $LANG, $LC_ALL, $LC_... $LANG is used to set to the default locale. For example, if the locale values are pt_BR, then the language is set to (Brazilian) Portuguese and Brazilian practice is used where relevant. Different aspects of localization are controlled by individual $LC_-variables ($LC_CTYPE, $LC_COLLATE, $LC_DATE etc.). $LC_ALL can be used to force the same locale for all aspects. $TZ Refers to time zone. It can be in several formats, either specifying the time zone itself or referencing a file (in /usr/share/zoneinfo). $BROWSER Contains a colon-separated list of a user's web browser preferences, for use by programs that need to allow the user to view content at a URL. The browsers in the list are intended to be attempted from first to last, stopping after the first one that succeeds. This arrangement allows for fallback behavior in different environments, e.g., in an X11 environment, a graphical browser (such as Firefox) can be used, but in a console environment a terminal-base browser (such a Lynx) can be used. A %s token may be present to specify where the URL should be placed; otherwise the browser should be launched with the URL as the first argument.[5][6][7][8][9]

 DOS [ edit ]

 Under DOS, the master environment is provided by the primary command processor, which inherits the pre-environment defined in CONFIG.SYS when first loaded. Its size can be configured through the COMMAND /E:n parameter between 160[10] and 32767[10] bytes. Local environment segments inherited to child processes are typically reduced down to the size of the contents they hold. Some command-line processors (like 4DOS) allow to define a minimum amount of free environment space that will be available when launching secondary shells.[10] While the content of environment variables remains unchanged upon storage, their names (without the "%") are always converted to uppercase, with the exception of pre-environment variables defined via the CONFIG.SYS directive SET under DR DOS 6.0 and higher[11][12] (and only with SWITCHES=/L (for "allow lowercase names") under DR-DOS 7.02 and higher).[10][13] In principle, MS-DOS 7.0 and higher also supports lowercase variable names (%windir%), but provides no means for the user to define them. Environment variable names containing lowercase letters are stored in the environment just like normal environment variables, but remain invisible to most DOS software, since they are written to expect uppercase variables only.[10][11][12] Some command processors limit the maximum length of a variable name to 80 characters.[10] While principally only limited by the size of the environment segment, some DOS and 16-bit Windows programs[10][nb 1] do not expect the contents of environment variables to exceed 128 characters. DR-DOS COMMAND.COM supports environment variables up to 255, 4DOS even up to 512 characters.[10] Since COMMAND.COM can be configured (via /L:128..1024) to support command lines up to 1024 characters internally under MS-DOS 7.0 and higher, environment variables should be expected to contain at least 1024 characters as well. In some versions of DR-DOS, the environment passed to drivers, which often do not need their environment after installation, can be shrunken or relocated through SETENV or INSTALL[HIGH]/LOADHIGH options /Z (zero environment), /D[:loaddrive] (substitute drive, e.g. B:TSR.COM) and /E (relocate environment above program) in order to minimize the driver's effectively resulting resident memory footprint.[14][13][11][15][16][17]

 In batch mode, non-existent environment variables are replaced by a zero-length string.

 Standard environment variables or reserved environment variables include:

 %APPEND% (supported since DOS 3.3) This variable contains a semicolon-delimited list of directories in which to search for files. It is usually changed via the APPEND /E command, which also ensures that the directory names are converted into uppercase. Some DOS software actually expects the names to be stored in uppercase and the length of the list not to exceed 121[10] characters, therefore the variable is best not modified via the SET command. Long filenames containing spaces or other special characters must not be quoted ("). %CONFIG% (supported since MS-DOS 6.0 and PC DOS 6.1, also supported by ROM-DOS[18]) This variable holds the symbolic name of the currently chosen boot configuration. It is set by the DOS BIOS (IO.SYS, IBMBIO.COM, etc.) to the name defined by the corresponding CONFIG.SYS directive MENUITEM before launching the primary command processor. Its main purpose is to allow further special cases in AUTOEXEC.BAT and similar batchjobs depending on the selected option at boot time. This can be emulated under DR-DOS by utilizing the CONFIG.SYS directive SET like SET CONFIG=1. %CMDLINE% (introduced with 4DOS, also supported since MS-DOS 7.0) This variable contains the fully expanded text of the currently executing command line. It can be read by applications to detect the usage of and retrieve long command lines, since the traditional method to retrieve the command line arguments through the PSP (or related API functions) is limited to 126 characters and is no longer available when FCBs get expanded or the default DTA is used. While 4DOS supports longer command lines, COMMAND.COM still only supports a maximum of 126 characters at the prompt by default (unless overridden with /U:128..255 to specify the size of the command line buffer), but nevertheless internal command lines can become longer through f.e. variable expansion (depending on /L:128..1024 to specify the size of the internal buffer). In addition to the command-line length byte in the PSP, the PSP command line is normally limited by ASCII-13, and command lines longer than 126 characters will typically be truncated by having an ASCII-13 inserted at position 127,[12] but this cannot be relied upon in all scenarios.[12][nb 2] The variable will be suppressed for external commands invoked with a preceding @-symbol like in @XCOPY ... for backward compatibility and in order to minimize the size of the environment when loading non-relocating terminate-and-stay-resident programs. Some beta versions of Windows Chicago used %CMDLINE% to store only the remainder of the command line excessing 126 characters instead of the complete command line.[11][12] %COMSPEC% (supported since DOS 2.0) This variable contains the full 8.3 path to the command processor, typically C:\COMMAND.COM or C:\DOS\COMMAND.COM. It must not contain long filenames, but under DR-DOS it may contain file and directory passwords. It is set up by the primary command processor to point to itself (typically reflecting the settings of the CONFIG.SYS directive SHELL), so that the resident portion of the command processor can reload its transient portion from disk after the execution of larger programs. The value can be changed at runtime to reflect changes in the configuration, which would require the command processor to reload itself from other locations. The variable is also used when launching secondary shells. %COPYCMD% (supported since MS-DOS 6.2 and PC DOS 6.3, also supported by ROM-DOS[18]) Allows a user to specify the /Y switch (to assume "Yes" on queries) as the default for the COPY, XCOPY, and MOVE commands. A default of /Y can be overridden by supplying the /-Y switch on the command line. The /Y switch instructs the command to replace existing files without prompting for confirmation. %DIRCMD% (supported since MS-DOS 5.0 and PC DOS 5.0, also supported by ROM-DOS[18]) Allows a user to specify customized default parameters for the DIR command, including file specifications. Preset default switches can be overridden by providing the negative switch on the command line. For example, if %DIRCMD% contains the /W switch, then it can be overridden by using DIR /-W at the command line. This is similar to the environment variable %$DIR% under DOS Plus[19] and a facility to define default switches for DIR through its /C or /R switches under DR-DOS COMMAND.COM.[11] %DIRCMD% is also supported by the external SDIR.COM/DIR.COM Stacker commands under Novell DOS 7 and higher.[11] %LANG% (supported since MS-DOS 7.0) This variable is supported by some tools to switch the locale for messages in multilingual issues. %LANGSPEC% (supported since MS-DOS 7.0) This variable is supported by some tools to switch the locale for messages in multilingual issues. %NO_SEP% (supported since PC DOS 6.3 and DR-DOS 7.07) This variable controls the display of thousands-separators in messages of various commands. Issued by default, they can be suppressed by specifying SET NO_SEP=ON or SET NO_SEP=1 under PC DOS. DR-DOS additionally allows to override the system's thousands-separator displayed as in f.e. SET NO_SEP=..[10] %PATH% (supported since DOS 2.0) This variable contains a semicolon-delimited list of directories in which the command interpreter will search for executable files. Equivalent to the Unix $PATH variable (but some DOS and Windows applications also use the list to search for data files similar to $LD_LIBRARY_PATH on Unix-like systems). It is usually changed via the PATH (or PATH /E under MS-DOS 6.0) command, which also ensures that the directory names are converted into uppercase. Some DOS software actually expects the names to be stored in uppercase and the length of the list not to exceed 123[10] characters,[nb 1] therefore the variable should better not be modified via the SET command.[10] Long filenames containing spaces or other special characters must not be quoted ("). By default, the current directory is searched first, but some command-line processors like 4DOS allow "." (for "current directory") to be included in the list as well in order to override this search order; some DOS programs are incompatible with this extension.[10] %PROMPT% (supported since DOS 2.0) This variable contains a $-tokenized string defining the display of the prompt. It is usually changed via the PROMPT command. %TEMP% (and %TMP%) These variables contain the path to the directory where temporary files should be stored. Operating system tools typically only use %TEMP%, whereas third-party programs also use %TMP%. Typically %TEMP% takes precedence over %TMP%.

 The DR-DOS family supports a number of additional standard environment variables including:

 %BETA% This variable contains an optional message displayed by some versions (including DR DOS 3.41) of COMMAND.COM at the startup of secondary shells.[20] %DRDOSCFG%/%NWDOSCFG%/%OPENDOSCFG% This variable contains the directory[21] (without trailing "\") where to search for .INI and .CFG configuration files (that is, DR-DOS application specific files like TASKMGR.INI, TASKMAX.INI, VIEWMAX.INI, FASTBACK.CFG etc., class specific files like COLORS.INI, or global files like DRDOS.INI, NWDOS.INI, OPENDOS.INI, or DOS.INI), as used by the INSTALL and SETUP commands and various DR-DOS programs like DISKOPT, DOSBOOK, EDIT, FBX, FILELINK, LOCK, SECURITY.OVL/NWLOGIN.EXE, SERNO, TASKMAX, TASKMGR, VIEWMAX, or UNDELETE.[11] It must not contain long filenames. %DRCOMSPEC% This variable optionally holds an alternative path to the command processor taking precedence over the path defined in the %COMSPEC% variable, optionally including file and directory passwords. Alternatively, it can hold a special value of "ON" or "1" in order to enforce the usage of the %COMSPEC% variable even in scenarios where the %COMSPEC% variable may point to the wrong command-line processor, for example, when running some versions of the DR-DOS SYS command under a foreign operating system.[22] %DRSYS% Setting this variable to "ON" or "1" will force some versions of the DR-DOS SYS command to work under foreign operating systems instead of displaying a warning.[22] %FBP_USER% Specifies the user name used by the FastBack command FBX and {user}.FB configuration files under Novell DOS 7.[11] %HOMEDIR% This variable may contain the home directory under DR-DOS (including DR DOS 5.0 and 6.0).[11][20] %INFO% In some versions of DR-DOS COMMAND.COM this variable defines the string displayed by the $I token of the PROMPT command.[20] It can be used, for example, to inform the user how to exit secondary shells. %LOGINNAME% In some versions of DR-DOS COMMAND.COM this variable defines the user name displayed by the $U token of the PROMPT command, as set up by f.e. login scripts for Novell NetWare.[10][11][20] See also the similarly named pseudo-variable %LOGIN_NAME%. %MDOS_EXEC% This variable can take the values "ON" or "OFF" under Multiuser DOS. If enabled, the operating system permits applications to shell out to secondary shells with the DOS Program Area (DPA) freed in order to have maximum DOS memory available for secondary applications instead of running them in the same domain as under DOS.[23][24] %NOCHAR% This variable can be used to define the character displayed by some commands in messages for "No" in [Y,N] queries, thereby overriding the current system default (typically "N" in English versions of DR-DOS). If it contains a string, only the first character, uppercased, will be taken. Some commands also support a command line parameter /Y to automatically assume "Yes" on queries, thereby suppressing such prompts. If, however, the parameter /Y:yn is used to specify the "Yes"/"No" characters (thereby overriding any %NOCHAR% setting), queries are not suppressed. See also the related CONFIG.SYS directive NOCHAR and the environment variable %YESCHAR%.[22] %NOSOUND% Setting this variable to "ON" or "1" will disable default beeps issued by some DR-DOS commands in certain situations such as to inform the user of the completion of some operation, that user interaction is required, or when a wrong key was pressed. Command line options to specifically enable certain beeps will override this setting. %OS% This variable contains the name of the operating system in order to distinguish between different DOS-related operating systems of Digital Research-origin in batch jobs and applications.[21] Known values include "DOSPLUS" (DOS Plus 1.2 in DOS emulation), "CPCDOS 4.1" (DOS Plus 1.2 in CP/M emulation), "DRDOS" (DR DOS 3.31-6.0, DR DOS Panther, DR DOS StarTrek, DR-DOS 7.02[21]-7.05), "EZDOS" (EZ-DOS 3.41), "PALMDOS" and "NetWare PalmDOS" (PalmDOS 1.0), "NWDOS" (Novell DOS 7), "NWDOS7" (Novell DOS 7 Beta), "OPENDOS" (Caldera OpenDOS 7.01, Caldera DR-OpenDOS 7.02), "CDOS" (Concurrent DOS, Concurrent DOS XM), "CPCDOS" (Concurrent PC DOS), "CDOS386" (Concurrent DOS 386), "DRMDOS" (DR Multiuser DOS), "MDOS" (CCI Multiuser DOS),[23] "IMSMDOS" (IMS Multiuser DOS), "REAL32" (REAL/32).[11][25] MS-DOS INTERSVR looks for a value of "DRDOS" as well.[25] See also the identically named environment variable %OS% later introduced in the Windows NT family. %PEXEC% In some versions of DR-DOS this variable defines the command executed by the $X token of the PROMPT command before COMMAND.COM displays the prompt after returning from external program execution.[11][21] %SWITCHAR% This variable defines the SwitChar to be used for argument parsing by some DR-DOS commands. If defined, it overrides the system's current SwitChar setting. The only accepted characters are "/" (DOS style), "-" (Unix style) and "[" (CP/M style). See also the related CONFIG.SYS directive SWITCHAR (to set the system's SwitChar setting) and the %/% system information variable in some issues of DR-DOS COMMAND.COM (to retrieve the current setting for portable batchjobs). %TASKMGRWINDIR% This variable specifies the directory, where the Windows SYSTEM.INI to be used by the DR-DOS TASKMGR multitasker is located, overriding the default procedure to locate the file.[11] %VER% This variable contains the version of the operating system in order to distinguish between different versions of DR-DOS in batch jobs and in the display of the VER command.[21] It is also used for the $V token of the PROMPT command and affects the value returned by the system information variable %OS_VERSION%. Known values include "1.0" (PalmDOS 1.0), "1.2" (DOS Plus 1.2 in DOS emulation), "2.0" (Concurrent DOS 386 2.0), "3.0" (Concurrent DOS 386 3.0), "3.31" (DR DOS 3.31), "3.32" (DR DOS 3.32), "3.33" (DR DOS 3.33), "3.34" (DR DOS 3.34), "3.35" (DR DOS 3.35), "3.40" (DR DOS 3.40), "3.41" (DR DOS 3.41, EZ-DOS 3.41), "3.41T" (DR DOS 3.41T), "4.1" (Concurrent PC DOS 4.1), "5.0" (DR DOS 5.0, DR Multiuser DOS 5.0), "5.1" (Novell DR Multiuser DOS 5.1), "6.0" (DR Concurrent DOS XM 6.0, DR DOS 6.0), "6.2" (DR Concurrent DOS XM 6.2), "7" (Novell DOS 7, Caldera OpenDOS 7.01, DR-DOS 7.02-7.05), "7.00" (CCI Multiuser DOS 7.00), "7.07" (DR-DOS 7.07), "7.1" (IMS Multiuser DOS 7.1), "7.21" (CCI Multiuser DOS 7.21),[23] "7.22" (CCI Multiuser DOS 7.22) etc.[11][25][23] %YESCHAR% This variable can be used to define the character displayed by some commands in messages for "Yes" in [Y,N] queries, thereby overriding the current system default (typically "Y" in English versions of DR-DOS). If it contains a string, only the first character, uppercased, will be taken. Some commands also support a command line parameter /Y to automatically assume "Yes" on queries, thereby suppressing such prompts. If, however, the parameter /Y:y is used to specify the "Yes" character (thereby overriding any %YESCHAR% setting), queries are not suppressed. See also the related CONFIG.SYS directive YESCHAR and the environment variable %NOCHAR%.[22] %$CLS% This variable defines the control sequence to be sent to the console driver to clear the screen when the CLS command is issued, thereby overriding the internal default ("←[2J" under DR-DOS, "←E" under DOS Plus 1.2 on Amstrad machines[19] as well as under Concurrent DOS, Multiuser DOS, and REAL/32 for VT52 terminals, or "←+" under Multiuser DOS for ASCII terminals).[23] If the variable is not defined and no ANSI.SYS console driver is detected, the DR-DOS COMMAND.COM will directly clear the screen via INT 10h/AH=00h BIOS function, like MS-DOS/PC DOS COMMAND.COM does. A special \nnn-notation for octal numbers is supported to allow the definition of special characters like ESC (ASCII-27 = "←" = 1Bh = 33o), as f.e. in SET $CLS=\033[2J. To send the backslash ("\") itself, it can be doubled "\\".[11][20][23] %$DIR% Supported by DOS Plus accepting the values "L" (long) or "W" (wide) to change the default layout of directory listings with DIR. Can be overridden using the command line options /L or /W.[20][19] See also the similar environment variable %DIRCMD% and the DIR options /C and /R of the DR-DOS COMMAND.COM.[11] %$PAGE% Supported by DOS Plus accepting the values "ON" or "OFF" for pagination control. Setting this to "ON" has the same affect as adding /P to commands supporting it (like DIR or TYPE).[20][19] %$LENGTH% Used by DOS Plus to define the screen length of the console in lines. This is used to control in a portable way when the screen output should be temporarily halted until a key is pressed in conjunction with the /P option supported by various commands or with automatic pagnination.[20][19] See also the related environment variables %$WIDTH% and %DIRSIZE% as well as the similar pseudo-variable %_ROWS%. %$WIDTH% Used by DOS Plus to define the screen width of the console in columns. This is used to control in a portable way the formatting of the screen output of commands like DIR /W or TYPE filename.[20][19] See also the related environment variables %$LENGTH% and %DIRSIZE% as well as the similar pseudo-variable %_COLUMNS%. %$SLICE% Used by DOS Plus accepting a numerical value to control the foreground/background time slicing of multitasking programs.[20][19] See also the DOS Plus command SLICE. %$ON% This variable can hold an optional control sequence to switch text highlighting, reversion or colorization on. It is used to emphasize or otherwise control the display of the file names in commands like TYPE wildcard, for example SET $ON=\033[1m with ANSI.SYS loaded or SET $ON=\016 for an IBM or ESC/P printer. For the special \nnn octal notation supported, see %$CLS%.[11][19] While the variable is undefined by default under DOS Plus and DR-DOS, the Multiuser DOS default for an ASCII terminal equals SET $ON=\033p.[20][23] See also the related environment variable %$OFF%. %$OFF% This variable can hold an optional control sequence to switch text highlighting, reversion or colorization off. It is used to return to the normal output after the display of file names in commands like TYPE wildcard, for example SET $OFF=\033[0m with ANSI.SYS loaded or SET $OFF=\024 for an IBM or ESC/P printer. For the special \nnn octal notation supported, see %$CLS%.[11][19] While the variable is undefined by default under DOS Plus and DR-DOS, the Multiuser DOS default for an ASCII terminal equals SET $OFF=\033q.[20][23] See also the related environment variable %$ON%. %$HEADER% This variable can hold an optional control sequence issued before the output of the file contents in commands like TYPE under DR-DOS 7.02 and higher. It can be used for highlighting, pagination or formatting, f.e. when sending the output to a printer, i.e. SET $HEADER=\017 for an IBM or ESC/P printer. For the special \nnn octal notation supported, see %$CLS%.[20] See also the related environment variable %$FOOTER%. %$FOOTER% This variable can hold an optional control sequence issued after the output of the file contents in commands like TYPE under DR-DOS 7.02 and higher. It is used to return to the normal output format, i.e. SET $FOOTER=\022\014 in the printer example above. For the special \nnn octal notation supported, see %$CLS%.[20] See also the related environment variable %$HEADER%.

 Datalight ROM-DOS supports a number of additional standard environment variables as well including:

 %DIRSIZE% This variable is used to define non-standard screen sizes rows[,cols] for DIR options /P and /W (similar to %$LENGTH% and %$WIDTH% under DOS Plus).[18] %NEWFILE% This variable is automatically set to the first parameter given to the CONFIG.SYS directive NEWFILE.[18]

 %TZ%, %COMM%, %SOCKETS%, %HTTP_DIR%, %HOSTNAME% and %FTPDIR% are also used by ROM-DOS.[18]

 OS/2 [ edit ]

 %BEGINLIBPATH% Contains a semicolon-separated list of directories which are searched for DLLs before the directories given by the %LIBPATH% variable (which is set during system startup with the special CONFIG.SYS directive LIBPATH). It is possible to specify relative directories here, including "." for the current working directory. See also the related environment variable %ENDLIBPATH%. %ENDLIBPATH% a list of directories to be searched for DLLs like %BEGINLIBPATH%, but searched after the list of directories in %LIBPATH%.

 Windows [ edit ]

 System path variables[ citation needed ] refer to locations of critical operating system resources, and as such generally are not user-dependent.

 %APPDATA% Contains the full path to the Application Data directory of the logged-in user. Does not work on Windows NT 4.0 SP6 UK. %LOCALAPPDATA% This variable is the temporary files of Applications. Its uses include storing of desktop themes, Windows error reporting, caching and profiles of web browsers. %ComSpec%/%COMSPEC% The %ComSpec% variable contains the full path to the command processor; on the Windows NT family of operating systems, this is cmd.exe, while on Windows 9x, %COMSPEC% is COMMAND.COM. %OS% The %OS% variable contains a symbolic name of the operating system family to distinguish between differing feature sets in batchjobs. It resembles an identically named environment variable %OS% found in all DOS-related operating systems of Digital Research-origin like Concurrent DOS, Multiuser DOS, REAL/32, DOS Plus, DR DOS, Novell DOS and OpenDOS. %OS% always holds the string "Windows_NT" on the Windows NT family.[26] %PATH% This variable contains a semicolon-delimited (do not put spaces in between) list of directories in which the command interpreter will search for an executable file that matches the given command. Environment variables that represent paths may be nested within the %PATH% variable, but only at one level of indirection. If this sub-path environment variable itself contains an environment variable representing a path, %PATH% will not expand properly in the variable substitution. Equivalent to the Unix $PATH variable. %ProgramFiles%, %ProgramFiles(x86)%, %ProgramW6432% The %ProgramFiles% variable points to the Program Files directory, which stores all the installed programs of Windows and others. The default on English-language systems is "C:\Program Files". In 64-bit editions of Windows (XP, 2003, Vista), there are also %ProgramFiles(x86)%, which defaults to "C:\Program Files (x86)", and %ProgramW6432%, which defaults to "C:\Program Files". The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit (this is caused by Windows-on-Windows 64-bit redirection). %CommonProgramFiles% This variable points to the Common Files directory. The default is "C:\Program Files\Common Files" in the English version of Windows. %OneDrive% The %OneDrive% variable is a special system-wide environment variable found on Windows NT and its derivatives. Its value is the path of where (if installed and setup) the Onedrive directory is located. The value of %OneDrive% is in most cases "C:\Users\{Username}\OneDrive\". %SystemDrive% The %SystemDrive% variable is a special system-wide environment variable found on Windows NT and its derivatives. Its value is the drive upon which the system directory was placed. The value of %SystemDrive% is in most cases "C:". %SystemRoot% The %SystemRoot% variable is a special system-wide environment variable found on the Windows NT family of operating systems. Its value is the location of the system directory, including the drive and path. The drive is the same as %SystemDrive% and the default path on a clean installation depends upon the version of the operating system. By default:
 * Windows XP and newer versions use "\WINDOWS".
 * Windows 2000, NT 4.0 and NT 3.1 use "\WINNT".
 * Windows NT 3.5 and NT 3.51 uses "\WINNT35".
 * Windows NT 4.0 Terminal Server uses "\WTSRV".
 %windir% This variable points to the Windows directory. (On the Windows NT family of operating systems, it is identical to the %SystemRoot% variable). Windows 95–98 and Windows ME are, by default, installed in "C:\Windows". For other versions of Windows, see the %SystemRoot% entry above.

 User management variables[ citation needed ] store information related to resources and settings owned by various user profiles within the system. As a general rule, these variables do not refer to critical system resources or locations that are necessary for the OS to run.

 %ALLUSERSPROFILE% (%PROGRAMDATA% since Windows Vista) This variable expands to the full path to the All Users profile directory. This profile contains resources and settings that are used by all system accounts. Shortcut links copied to the All Users\' Start menu or Desktop directories will appear in every user's Start menu or Desktop, respectively. %USERDOMAIN% The name of the Workgroup or Windows Domain to which the current user belongs. The related variable, %LOGONSERVER%, holds the hostname of the server that authenticated the current user's login credentials (name and password). For home PCs and PCs in a workgroup, the authenticating server is usually the PC itself. For PCs in a Windows domain, the authenticating server is a domain controller (a primary domain controller, or PDC, in Windows NT 4-based domains). %USERPROFILE% A special system-wide environment variable found on Windows NT and its derivatives. Its value is the location of the current user's profile directory, in which is found that user's HKCU registry hive (NTUSER). Users can also use the %USERNAME% variable to determine the active users login identification.

 Optional System variables[ citation needed ] are not explicitly specified by default but can be used to modify the default behavior of certain built-in console commands. These variables also do not need to be explicitly specified as command line arguments.

 Default values [ edit ]

 The following tables shows typical default values of certain environment variables under English versions of Windows as they can be retrieved under CMD.

 (Some of these variables are also defined when running COMMAND.COM under Windows, but differ in certain important details: Under COMMAND.COM, the names of environment variable are always uppercased. Some, but not all variables contain short 8.3 rather than long file names. While some variables present in the CMD environment are missing, there are also some variables specific to the COMMAND environment.)

 Variable Locale specific Windows XP (CMD) Windows Vista and later (CMD)   
 %ALLUSERSPROFILE% [27] Yes C:\Documents and Settings\All Users C:\ProgramData[27]   
 %APPDATA% [27] Yes C:\Documents and Settings\{username}\Application Data C:\Users\{username}\AppData\Roaming[27]  
 %CommonProgramFiles% [27] Yes C:\Program Files\Common Files C:\Program Files\Common Files[27]  
 %CommonProgramFiles(x86)% [27] Yes C:\Program Files (x86)\Common Files (only in 64-bit version) C:\Program Files (x86)\Common Files (only in 64-bit version)[27]  
 %CommonProgramW6432% [27] Yes %CommonProgramW6432% (not supported, not replaced by any value) C:\Program Files\Common Files (only in 64-bit version)[27]  
 %COMPUTERNAME% No {computername} {computername}   
 %ComSpec% No C:\Windows\System32\cmd.exe C:\Windows\System32\cmd.exe   
 %HOMEDRIVE% [27] No C:  C:[27]   
 %HOMEPATH% [27] Yes \Documents and Settings\{username} \Users\{username}[27]   
 %LOCALAPPDATA% [27] Yes %LOCALAPPDATA% (not supported, not replaced by any value) C:\Users\{username}\AppData\Local[27]  
 %LOGONSERVER% No \\{domain_logon_server} \\{domain_logon_server}   
 %PATH% Yes C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths} C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths}  
 %PATHEXT% No .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.WSF;.WSH .com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc  
 %ProgramData% [27] Yes %ProgramData% (not supported, not replaced by any value) %SystemDrive% \ProgramData[27]   
 %ProgramFiles% [27] Yes %SystemDrive% \Program Files %SystemDrive% \Program Files[27]   
 %ProgramFiles(x86)% [27] Yes %SystemDrive% \Program Files (x86) (only in 64-bit version) %SystemDrive% \Program Files (x86) (only in 64-bit version)[27]  
 %ProgramW6432% [27] Yes %ProgramW6432% (not supported, not replaced by any value) %SystemDrive% \Program Files (only in 64-bit version)[27]  
 %PROMPT% No Code for current command prompt format, usually $P$G Code for current command prompt format, usually $P$G  
 %PSModulePath% %PSModulePath% (not supported, not replaced by any value) %SystemRoot% \system32\WindowsPowerShell\v1.0\Modules\  
 %PUBLIC% [27] Yes %PUBLIC% (not supported, not replaced by any value) %SystemDrive% \Users\Public[27]   
 %SystemDrive% [27] No C:  C:[27]   
 %SystemRoot% [27] No The Windows directory, usually C:\Windows, formerly C:\WINNT %SystemDrive% \Windows[27]   
 %TEMP% [27] and %TMP% [27] Yes %SystemDrive% \Documents and Settings\{username}\Local Settings\Temp %SystemRoot% \TEMP (for system environment variables %TMP% and %TEMP% ), %USERPROFILE% \AppData\Local\Temp[27] (for user environment variables %TMP% and %TEMP% )
 %USERDOMAIN% No {userdomain}  {userdomain}   
 %USERNAME% No {username}  {username}   
 %USERPROFILE% [27] Yes %SystemDrive% \Documents and Settings\{username} %SystemDrive% \Users\{username}[27]  
 %windir% [27] No %SystemDrive% \WINDOWS %SystemDrive% \Windows[27]   
 

 In this list, there is no environment variable that refers to the location of the user's My Documents directory, so there is no standard method for setting a program's home directory to be the My Documents directory.

 Pseudo-environment variables [ edit ]

 The command processors in DOS and Windows also support pseudo-environment variables. These are values that are fetched like environment variables, but are not truly stored in the environment but computed when requested.

 DOS [ edit ]

 Besides true environment variables, which are statically stored in the environment until changed or deleted, a number of pseudo-environment variables exist for batch processing.

 The so-called replacement parameters or replaceable parameters (Microsoft / IBM terminology) aka replacement variables (Digital Research / Novell / Caldera terminology)[21] or batch file parameters (JP Software terminology)[10] %1..%9 and %0 can be used to retrieve the calling parameters of a batchjob, see SHIFT. In batchjobs, they can be retrieved just like environment variables, but are not actually stored in the environment.

 Some command-line processors (like DR-DOS COMMAND.COM,[21] Multiuser DOS MDOS.COM/TMP.EXE (Terminal Message Process), JP Software 4DOS, 4OS2, 4NT, Take Command and Windows cmd.exe) support a type of pseudo-environment variables named system information variables (Novell / Caldera terminology)[21] or internal variables (JP Software terminology),[10] which can be used to retrieve various possibly dynamic, but read-only information about the running system in batch jobs. The returned values represent the status of the system in the moment these variables are queried; that is, reading them multiple times in a row may return different values even within the same command; querying them has no direct effect on the system. Since they are not stored in the environment, they are not listed by SET and do not exist for external programs to retrieve. If a true environment variable of the same name is defined, it takes precedence over the corresponding variable until the environment variable is deleted again. They are not case-sensitive. While almost all such variables are prefixed with an underscore ("_") by 4DOS etc. by convention (f.e. %_SECOND%),[10] they are not under DR-DOS COMMAND.COM (f.e. %OS_VERSION%).

 In addition, 4DOS, 4OS2, 4NT, and Take Command also support so called variable functions,[10] including user-definable ones. They work just like internal variables, but can take optional parameters (f.e. %@EVAL[]%) and may even change the system status depending on their function.

 System information variables supported by DR-DOS COMMAND.COM:

 %AM_PM% This pseudo-variable returns the ante- or post-midday status of the current time. The returned string depends on the locale-specific version of DR-DOS, f.e. "am" or "pm" in the English version. It resembles an identically named identifier variable in Novell NetWare login scripts. %DAY% This pseudo-variable returns the days of the current date in a 2-digit format with leading zeros, f.e. "01".."31". See also the similar pseudo-variable %_DAY%. It resembles an identically named identifier variable in Novell NetWare login scripts. %DAY_OF_WEEK% This pseudo-variable returns the day name of the week in a 3-character format. The returned string depends on the locale-specific version of DR-DOS, f.e. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", or "Sat" in the English version. It resembles an identically named identifier variable in Novell NetWare login scripts. %ERRORLEVEL% In COMMAND.COM of DR-DOS 7.02 and higher, this pseudo-variable returns the last error level returned by an external program or the RETURN command, f.e. "0".."255".[28][29] See also the identically named pseudo-variable %ERRORLEVEL% under Windows and the IF ERRORLEVEL conditional command. %ERRORLVL% In DR-DOS 7.02 and higher, this pseudo-variable returns the last error level in a 3-digit format with leading zeros, f.e. "000".."255".[28][29] Under Multiuser DOS, this is a true environment variable automatically updated by the shell to the return code of exiting programs.[23] See also the related pseudo-variable %ERRORLEVEL% under DR-DOS and the IF ERRORLEVEL command. %GREETING_TIME% This pseudo-variable returns the 3-level day greeting time. The returned string depends on the locale-specific version of DR-DOS, f.e. "morning", "afternoon", or "evening" in the English version. It resembles an identically named identifier variable in Novell NetWare login scripts. %HOUR% This pseudo-variable returns the hours of the current time in 12-hour format without leading zeros, f.e. "1".."12". It resembles an identically named identifier variable in Novell NetWare login scripts. %HOUR24% This pseudo-variable returns the hours of the current time in 24-hour format in a 2-digit format with leading zeros, f.e. "00".."23". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable %_HOUR%. %MINUTE% This pseudo-variable returns the minutes of the current time in a 2-digit format with leading zeros, f.e "00".."59". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable %_MINUTE%. %MONTH% This pseudo-variable returns the months of the current date in a 2-digit format with leading zeros, f.e. "01".."12". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable %_MONTH%. %MONTH_NAME% This pseudo-variable returns the month name of the current date. The returned string depends on the locale-specific version of DR-DOS, f.e. "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", or "December" in the English version. It resembles an identically named identifier variable in Novell NetWare login scripts. %NDAY_OF_WEEK% This pseudo-variable returns the number of day of the current week, f.e. "1".."7" (with "1" for Sunday). It resembles an identically named identifier variable in Novell NetWare login scripts. %OS_VERSION% This pseudo-variable returns the version of the operating system depending on the current setting of the environment variable %VER%. If %VER% is not defined, %OS_VERSION% returns "off". It resembles an identically named identifier variable in Novell NetWare login scripts, which may return versions also for non-DR-DOS versions of DOS. %SECOND% This pseudo-variable returns the seconds of the current time in a 2-digit format with leading zeros, f.e. "00".."59". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable %_SECOND%. %SHORT_YEAR% This pseudo-variable returns the year of the current date in a 2-digit format with leading zeros, f.e. "93".."99", "00".."92". It resembles an identically named identifier variable in Novell NetWare login scripts. %YEAR% and %_YEAR% Supported since Novell DOS 7, the %YEAR% pseudo-variable returns the year of the current date in a 4-digit format, f.e. "1980".."2099". It resembles an identically named identifier variable in Novell NetWare login scripts. DR-DOS 7.02 and higher added %_YEAR% for compatibility with 4DOS, returning the same value.[10] %/% In COMMAND.COM of DR-DOS 7.02 and higher, this pseudo-variable returns the current SwitChar setting of the system, either "/" (DOS style) or "-" (Unix style).[30][31] See also the related CONFIG.SYS directive SWITCHAR and the environment variable %SWITCHAR%. %_CODEPAGE% This pseudo-variable returns the systems' current code page ("1".."65533"), f.e. "437", "850", "858". This variable was originally introduced by 4DOS,[10] but also became available with COMMAND.COM since DR-DOS 7.02. See also the CHCP command. %_COLUMNS% This pseudo-variable returns the current number of screen columns depending on the display mode, f.e. "40", "80", "132", etc. This variable was originally introduced by 4DOS,[10] but also became available with COMMAND.COM since DR-DOS 7.02. See also a similar environment variable %$WIDTH% under DOS Plus. %_COUNTRY% This pseudo-variable returns the systems' current country code ("1".."65534"), f.e. "1" for USA, "44" for UK, "49" for Germany, "20049" with ISO 8601, "21049" with ISO 8601 and Euro support.[31][32] This variable was originally introduced by 4DOS,[10] but also became available with COMMAND.COM since DR-DOS 7.02. See also the CONFIG.SYS directive COUNTRY. %_DAY% This pseudo-variable returns the days of the current date without leading zeros, f.e. "1".."31". This variable was originally introduced by 4DOS,[10] but also became available with COMMAND.COM since DR-DOS 7.02. See also the similar pseudo-variable %DAY%. %_HOUR% This pseudo-variable returns the hours of the current time in 24-hour format without leading zeros, f.e. "0".."23". This variable was originally introduced by 4DOS,[10] but also became available with COMMAND.COM since DR-DOS 7.02. See also the similar pseudo-variable %HOUR24%. %_MINUTE% This pseudo-variable returns the minutes of the current time without leading zeros, f.e "0".."59". This variable was originally introduced by 4DOS,[10] but also became available with COMMAND.COM since DR-DOS 7.02. See also the similar pseudo-variable %MINUTE%. %_MONTH% This pseudo-variable returns the months of the current date without leading zeros, f.e. "1".."12". This variable was originally introduced by 4DOS,[10] but also became available with COMMAND.COM since DR-DOS 7.02. See also the similar pseudo-variable %MONTH%. %_ROWS% This pseudo-variable returns the current number of screen rows depending on the display mode, f.e. "25", "43", "50", etc. This variable was originally introduced by 4DOS,[10] but also became available with COMMAND.COM since DR-DOS 7.02. See a similar environment variable %$LENGTH% under DOS Plus. %_SECOND% This pseudo-variable returns the seconds of the current time without leading zeros, f.e. "0".."59". This variable was originally introduced by 4DOS,[10] but also became available with COMMAND.COM since DR-DOS 7.02. See also the similar pseudo-variable %SECOND%.

 System information variables supported by DR-DOS COMMAND.COM with networking loaded:

 %LOGIN_NAME% This pseudo-variable returns the user name. This always worked with NETX, but it will also work with Personal NetWare's ODI/VLM if the current drive is a PNW-mapped drive (otherwise an empty string is returned). See also the similarly named environment variable %LOGINNAME%. %P_STATION% This pseudo-variable returns the physical station number in a format "????????????". The value depends on the MAC address of the network adapter, but can be overridden. It resembles an identically named identifier variable in Novell NetWare login scripts. %STATION% This pseudo-variable returns the logical station number starting with "1" for the first client. The numbers are assigned by the file server and remain static for as long as the IPX connection remains established. It resembles an identically named identifier variable in Novell NetWare login scripts. %FULL_NAME% This pseudo-variable returns the full name of the logged in user, if available. It resembles an identically named identifier variable in Novell NetWare login scripts. See also the related pseudo-variable %LOGIN_NAME%.

 Windows [ edit ]

 Dynamic environment variables (also named internal variables or system information variables under DOS) are pseudo-environment variables supported by CMD.EXE when command-line extensions are enabled, and they expand to various discrete values whenever queried, that is, their values can change when queried multiple times even within the same command. While they can be used in batch jobs and at the prompt, they are not stored in the environment. Consequently, they are neither listed by SET nor do they exist for external programs to read. They are not case-sensitive.

 Indirectly, they are also supported under Windows' COMMAND.COM, which has been modified to internally call CMD.EXE to execute the commands.

 %CD% This pseudo-variable expands to the current directory equivalent to the output of the command CD when called without arguments. While a long filename can be returned under CMD.EXE depending on the current directory, the fact that the current directory will always be in 8.3 format under COMMAND.COM will cause it to return a short filename under COMMAND.COM, even when COMMAND internally calls CMD. %CMDCMDLINE% This pseudo-variable expands to the original startup parameters of CMD.EXE, f.e. "C:\Windows\system32\cmd.exe". Under Windows' COMMAND.COM, this may return something like "C:\Windows\system32\cmd.exe /c ..." due to the fact that COMMAND.COM calls CMD.EXE internally. %CMDEXTVERSION% This pseudo-variable expands to the version of the command-line extensions of CMD.EXE, if enabled (e.g. "1" under Windows NT, "2" under Windows 2000 and Windows XP). %DATE% This pseudo-variable expands to the current date. The date is displayed according to the current user's date format preferences. %ERRORLEVEL% This pseudo-variable expands to the last set error level, a value between "0" and "255" (without leading zeros).[28][33][29] External commands and some internal commands set error levels upon execution. See also the identically named pseudo-variable %ERRORLEVEL% under DR-DOS and the IF ERRORLEVEL command. %HIGHESTNUMANODENUMBER% This pseudo-variable returns the number of the highest NUMA node. %RANDOM% This pseudo-variable returns a random number between "0" and "32767". %TIME% This pseudo-variable returns the current time. The time is displayed according to the current user's time format preferences. If the %TIME% and %DATE% variables are both used, it is important to read them both in this particular order in rapid succession in order to avoid midnight-rollover problems.

 Other shells [ edit ]

 Unix-like shells have similar dynamically generated variables, bash's $RANDOM being a well-known example. However, since these shells have a concept of local variables, they are described as special local variables instead.[34]

 See also [ edit ]

 * Variable (computer science)
 * List of Unix commands
 * List of DOS commands
 * Special folder
 * Modules Environment
 * PWB shell
 * Windows Registry

 Notes [ edit ]

 1. ^ a b Applications not coping properly with environment variables longer than 128 characters include CadStar PCB , Checkit, Computer Select CD-ROM, RenderMan, VINES Network , Windows 3.0 , and Word for Windows 6.0 .
 2. ^ 4DOS and MS-DOS 7.0 set the length to 127 and insert ASCII-13 at this position, but Borland libraries set the length to the invalid value of 128 and do not insert an ASCII-13. For shorter command lines, 4DOS/ NDOS and DR-DOS also insert an ASCII-0 after the ASCII-13, but not when invoked vis INSTALL directive; MS-DOS doesn't.

 References [ edit ]

 1. ^ Robbins, Arnold; Beebe, Nelson H. F. (May 2005). Apandi, Tatiana; Randal, Allison; Witwer, Adam (eds.). Classic Shell Scripting (1 ed.). O'Reilly. ISBN 978-0-596-00595-5.
 2. ^ "unset - unset values and attributes of variables and functions – ". Commands & Utilities Reference, The Single UNIX Specification - The Open Group Base Specifications, IEEE Std 1003.1-2008 (Issue 7 ed.). The IEEE and The Open Group. 2016 [2001]. Archived from the original on 2017-12-18 . Retrieved 2017-12-18 .
 3. ^ fgrose (2015-07-31) [2011]. "The unset builtin command". Bash Hackers Wiki. Archived from the original on 2017-12-18 . Retrieved 2017-12-18 .
 4. ^ Jacobs, Mike; Koren, Alexander; Satran, Michael (2017-11-14). "Store and retrieve settings and other app data". Microsoft. Archived from the original on 2017-12-18 . Retrieved 2017-12-18 .
 5. ^ Raymond, Eric (2002-08-02) [Originally published 2001]. "The BROWSER project". Archived from the original on 2019-09-21 . Retrieved 2020-10-21 .
 6. ^ "LWN - Development". LWN.net. 2001-02-01. Archived from the original on 2019-02-08 . Retrieved 2020-10-21 . "Standardizing a BROWSER environment variable. Eric Raymond is promoting the use of a new environment variable, BROWSER, to complement the existing PAGER, MAILER, and EDITOR variables. This effort is being tested as an experiment in hacking social systems."
 7. ^ Špaček, Michal (2020-01-19) [First version published 2013]. "Env::Browser-0.06". metacpan.org. Archived from the original on 2020-10-21 . Retrieved 2020-10-21 . "Env::Browser - Process environment variable $BROWSER and run web browser"
 8. ^ "webbrowser — Convenient Web-browser controller". docs.python.org. Archived from the original on 2020-10-13 . Retrieved 2020-10-21 .
 9. ^ "DefaultWebBrowser - Debian Wiki". wiki.debian.org. 2020-06-10. Archived from the original on 2020-10-21 . Retrieved 2020-10-21 . "The environment variable BROWSER can be set to[…] always choose your desired browser."
 10. ^ a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab Brothers, Hardin; Rawson, Tom; Conn, Rex C.; Paul, Matthias R.; Dye, Charles E.; Georgiev, Luchezar I. (2002-02-27). 4DOS 8.00 online help.
 11. ^ a b c d e f g h i j k l m n o p q r Paul, Matthias R. (1997-07-30) [1994-05-01]. NWDOS-TIPs — Tips & Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds. MPDOSTIP. Release 157 (in German) (3 ed.). Archived from the original on 2016-11-04 . Retrieved 2014-08-06 . (NB. NWDOSTIP.TXT is a comprehensive work on Novell DOS 7 and OpenDOS 7.01 , including the description of many undocumented features and internals. The provided link points to a HTML-converted version of the file, which is part of the MPDOSTIP.ZIP collection.) [1]
 12. ^ a b c d e Paul, Matthias R. (1997-05-01) [1995-03-01]. "Hinweise zu JPSofts 4DOS 5.5b/c, 5.51, 5.52a und NDOS". MPDOSTIP (in German). Archived from the original on 2016-11-04 . Retrieved 2015-05-08 . (NB. The provided link points to a HTML-converted version of the 4DOS5TIP.TXT file, which is part of the MPDOSTIP.ZIP collection.) [2]
 13. ^ a b Paul, Matthias R. (1997-10-02). "Caldera OpenDOS 7.01/7.02 Update Alpha 3 IBMBIO.COM README.TXT". Archived from the original on 2003-10-04 . Retrieved 2009-03-29 . [3]
 14. ^ Paul, Matthias R. (1997-05-27) [1996]. "SETENV v1.11". Archived from the original on 2009-02-15 . Retrieved 2019-08-09 . "[…] SETENV […] to hide and later restore the […] pre-environment […] By using SETENV.COM you can save some KiloBytes of rare DOS memory […] depending on the number of drivers loaded by "INSTALL="/"INSTALLHIGH="/"HIINSTALL=" and the current size of the pre-environment. […] this original […] feature cannot be found in any known memory manager/optimizer. […]"
 15. ^ Paul, Matthias R. (2002-04-06). "Re: [fd-dev] ANNOUNCE: CuteMouse 2.0 alpha 1". freedos-dev. Archived from the original on 2020-02-07 . Retrieved 2020-02-07 . "[…] In CTMOUSE.ASM prepareTSR routine I found a comment in regard to the zero-environment. […] "DESQview" or "DRDOS" zero-env? […] release environment block […] skip if any problem […] zero-pad for "MEM" style utilities […]"
 16. ^ "PTS-DOS 2000 Pro User Manual" (PDF) . Archived (PDF) from the original on 2018-05-12 . Retrieved 2018-05-12 .
 17. ^ Paul, Matthias R. (2002-10-07). "Re: Run a COM file". Newsgroup: alt.msdos.programmer. Archived from the original on 2017-09-03 . Retrieved 2017-09-03 . [4]
 18. ^ a b c d e f Datalight, Inc.; GPvNO (April 2005) [1999]. "Datalight ROM-DOS User's Guide" (PDF) . Datalight, Inc. 3010-0200-0716. Archived (PDF) from the original on 2019-03-20 . Retrieved 2018-09-16 .
 19. ^ a b c d e f g h i Kotulla, Martin (November 1987). "Von CP/M zu MS-DOS, Teil 11" (PDF) . Professional Computing (PC) - Schneider International (in German). 3 (11): 100–103. Archived (PDF) from the original on 2019-04-24 . Retrieved 2018-05-20 .
 20. ^ a b c d e f g h i j k l m n Paul, Matthias R. (2002-03-26). "Updated CLS posted". freedos-dev mailing list. Archived from the original on 2018-10-04 . Retrieved 2014-08-06 .
 21. ^ a b c d e f g h Caldera DR-DOS 7.02 User Guide. Caldera, Inc. 1998 [1993, 1997]. Archived from the original on 2016-11-04 . Retrieved 2013-08-10 .
 22. ^ a b c d Paul, Matthias R. (2017-08-14) [2017-08-07]. "The continuing saga of Windows 3.1 in enhanced mode on OmniBook 300". MoHPC - the Museum of HP Calculators. Archived from the original on 2018-05-01 . Retrieved 2018-05-01 . "[…] set DRSYS=ON (optional to tell SYS you are aware of the fact that you're running it in a foreign environment and want to proceed anyway without having to individually ACK some warnings and extra info screens displayed in this scenario otherwise) […]"
 23. ^ a b c d e f g h i CCI Multiuser DOS 7.22 GOLD Online Documentation. Concurrent Controls, Inc. (CCI). 1997-02-10. HELP.HLP.
 24. ^ CCI Multiuser DOS 7.22 GOLD Installation Guide. Concurrent Controls, Inc. (CCI). 1997-02-10. PRINTDOC.HLP.
 25. ^ a b c Paul, Matthias R. (2002-02-20). "How to detect FreeCOM/FreeDOS in-batch?". freedos-dev mailing list. Archived from the original on 2018-11-06 . Retrieved 2014-08-06 .
 26. ^ Brink, Shawn (2018-11-17). "Environment Variables in Windows 10 - Complete List of Environment Variables in Windows 10". Windows Ten Forums. Archived from the original on 2019-03-27 . Retrieved 2019-04-24 .
 27. ^ a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag ah ai aj ak Schulz, Hajo (2014-10-02). "Ordner für spezielle Fälle — Die "benannten Ordner" in Windows aus User- und Entwicklersicht" [Special purpose folders — Windows' "named folders" from a user's and developer's perspective]. c't - magazin für computertechnik (in German). Heise Verlag. 2014 (22): 180–184. Archived from the original on 2016-07-09 . Retrieved 2019-04-08 .
 28. ^ a b c Paul, Matthias R. (1997-05-01) [1993-10-01]. BATTIPs — Tips & Tricks zur Programmierung von Batchjobs. MPDOSTIP (in German). 7: ERRORLEVEL abfragen. Archived from the original on 2017-08-23 . Retrieved 2017-08-23 . [5] [6] (NB. BATTIPS.TXT is part of MPDOSTIP.ZIP. The provided link points to a HTML-converted older version of the BATTIPS.TXT file.) [7]
 29. ^ a b c Auer, Eric; Paul, Matthias R.; Hall, Jim (2015-12-24) [2003-12-31]. "MS-DOS errorlevels". Archived from the original on 2015-12-24.
 30. ^ Paul, Matthias R. (1998-01-09). DELTREE.BAT R1.01 Extended file and directory delete. Caldera, Inc. Archived from the original on 2019-04-08 . Retrieved 2019-04-08 .
 31. ^ a b DR-DOS 7.03 WHATSNEW.TXT — Changes from DR-DOS 7.02 to DR-DOS 7.03. Caldera, Inc. 1998-12-24. Archived from the original on 2019-04-08 . Retrieved 2019-04-08 .
 32. ^ Paul, Matthias R. (2001-06-10) [1995]. "DOS COUNTRY.SYS file format" (COUNTRY.LST file) (1.44 ed.). Archived from the original on 2016-04-20 . Retrieved 2016-08-20 .
 33. ^ Allen, William; Allen, Linda. "Windows 95/98/ME ERRORLEVELs". Archived from the original on 2011-07-07.
 34. ^ "Shell Variables". Bash Reference Manual.

 Further reading [ edit ]

 * Chen, Raymond (2010-05-06). "What are these strange =C: environment variables?". The New Old Thing. Microsoft. Archived from the original on 2018-05-27 . Retrieved 2017-05-27 .

 External links [ edit ]

 * environ(7): user environment – Linux Programmer's Manual – Overview, Conventions and Miscellanea
 * environ(7) – FreeBSD Miscellaneous Information Manual
 * environ(7) – Darwin and macOS Miscellaneous Information Manual
 * environ(5) – Solaris 10 Standards, Environments and Macros Reference Manual
 * "Environment Variables Wiki". Archived from the original on 2019-04-27.
 * User Environment Variables
 * fix setx.exe not found bug
 * v 
 * t 
 * e 
 Unix command-line interface programs and shell builtins
  * cat 
  * chattr 
  * chmod 
  * chown 
  * chgrp 
  * cksum 
  * cmp 
  * cp 
  * dd 
  * du 
  * df 
  * file 
 File system * fuser 
  * ln 
  * ls 
  * mkdir 
  * mv 
  * pax 
  * pwd 
  * rm 
  * rmdir 
  * split 
  * tee 
  * touch 
  * type 
  * umask 
  * at 
  * bg 
  * crontab 
 Processes * fg 
  * kill 
  * nice 
  * ps 
  * time 
  * env 
  * exit 
  * logname 
  * mesg 
 User environment * talk 
  * tput 
  * uname 
  * who 
  * write 
  * awk 
  * basename 
  * comm 
  * csplit 
  * cut 
  * diff 
  * dirname 
  * ed 
  * ex 
  * fold 
  * head 
  * iconv 
  * join 
  * m4 
 Text processing * more 
  * nl 
  * paste 
  * patch 
  * printf 
  * read 
  * sed 
  * sort 
  * strings 
  * tail 
  * tr 
  * troff 
  * uniq 
  * vi 
  * wc 
  * xargs 
  * alias 
  * cd 
 Shell builtins * echo 
  * test 
  * unset 
  * wait 
 Searching * find 
  * grep 
 Documentation * man 
  * ar 
  * ctags 
  * lex 
 Software development * make 
  * nm 
  * strip 
  * yacc 
  * bc 
  * cal 
  * expr 
 Miscellaneous * lp 
  * od 
  * sleep 
  * true and false
 * Categories 
 + Standard Unix programs 
 + Unix SUS2008 utilities 
 * List 
 
 * v 
 * t 
 * e 
 Windows command-line programs and shell builtins
 * COMMAND.COM 
 * Command Prompt 
 * Windows PowerShell 
 * Recovery Console 
  * cd (chdir) 
  * dir 
 File system navigation * popd 
  * pushd 
  * tree 
  * attrib 
  * cacls 
  * cipher 
  * compact 
  * copy 
  * del (erase) 
  * deltree 
  * icacls 
  * mkdir (md) 
 File management * mklink 
  * move 
  * openfiles 
  * recover 
  * ren (rename) 
  * replace 
  * rmdir (rd) 
  * robocopy 
  * takeown 
  * xcopy 
  * expand 
  * extrac32 
 Archiving * extract 
  * makecab 
  * pax 
  * tar 
  * chkdsk 
  * convert 
  * defrag 
  * diskcomp 
  * diskcopy 
  * diskpart 
  * diskraid 
  * diskshadow 
  * drvspace 
 Disk management * fdisk 
  * format 
  * fsutil 
  * label 
  * manage-bde 
  * refsutil 
  * subst 
  * scandisk 
  * sys 
  * vol 
  * vssadmin 
  * at 
  * exit 
  * kill 
  * powercfg 
  * runas 
 Processes * sc 
  * schtasks 
  * shutdown 
  * start 
  * taskkill 
  * tasklist 
  * assoc 
  * ftype 
 Registry * reg 
  * regini 
  * regsvr32 
  * chcp 
  * cmdkey 
  * date 
  * graftabl 
  * mode 
  * path 
 User environment * set 
  * setver 
  * setx 
  * time 
  * title 
  * ver 
  * where 
  * whoami 
  * comp 
  * edit 
  * edlin 
 File contents * fc 
  * find 
  * findstr 
  * print 
  * type 
  * choice 
  * clip 
  * cscript 
  * doskey 
  * echo 
  * for 
 Scripting * forfiles 
  * goto 
  * if 
  * more 
  * pause 
  * prompt 
  * rem 
  * timeout 
  * arp 
  * bitsadmin 
  * curl 
  * getmac 
  * hostname 
  * ipconfig 
  * nbtstat 
  * net 
  * netsh 
  * netstat 
  * nslookup 
  * PathPing 
 Networking * ping 
  * rpcping 
  * route 
  * scp 
  * setspn 
  * sftp 
  * ssh 
  * ssh-add 
  * ssh-agent 
  * ssh-keygen 
  * ssh-keyscan 
  * tracert 
  * winrm 
  * winrs 
  * auditpol 
  * dispdiag 
  * driverquery 
  * eventcreate 
  * eventtriggers
  * logman 
  * mofcomp 
  * msiexec 
  * ntbackup 
  * pnpunattend 
  * pnputil 
  * REAgentC 
 Maintenance and care * relog 
  * sfc 
  * sxstrace 
  * systeminfo 
  * tracerpt 
  * typeperf 
  * w32tm 
  * WBAdmin 
  * wecutil 
  * wevtutil 
  * winmgmt 
  * winsat 
  * wmic 
  * bcdedit 
  * bootcfg 
 Boot management * bootsect 
  * fixboot 
  * fixmbr 
  * debug 
 Software development * exe2bin 
  * QBasic 
  * break 
  * cls 
  * dism 
  * dpath 
  * gpresult 
 Miscellaneous * gpupdate 
  * help 
  * MSCDEX 
  * pentnt 
  * tpmtool 
  * tpmvscmgr 
  * wsl 
 * List of DOS commands 
 * Environment variables 
 * Windows Support Tools 
 
 Retrieved from "https://en.wikipedia.org/w/index.php?title=Environment_variable&oldid=1135371324"
 Categories:
 * Windows commands
 * Operating system technology
 * Environment variables
 Hidden categories:
 * CS1 German-language sources (de)
 * Articles with short description
 * Short description is different from Wikidata
 * Use dmy dates from April 2019
 * Use list-defined references from January 2022
 * All articles with unsourced statements
 * Articles with unsourced statements from August 2014
 * This page was last edited on 24 January 2023, at 07:25 (UTC) .
 * Text is available under the Creative Commons Attribution-ShareAlike License 3.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.
 * Privacy policy
 * About Wikipedia
 * Disclaimers
 * Contact Wikipedia
 * Mobile view
 * Developers
 * Statistics
 * Cookie statement
 * 
 * 
An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.
 They were introduced in their modern form in 1979 with Version 7 Unix, so are included in all Unix operating system flavors and variants from that point onward including Linux and macOS. From PC DOS 2.0 in 1982, all succeeding Microsoft operating systems, including Microsoft Windows, and OS/2 also have included them as a feature, although with somewhat different syntax, usage and standard variable names.
Design[edit]
In all Unix and Unix-like systems, as well as on Windows, each process has its own separate set of environment variables. By default, when a process is created, it inherits a duplicate run-time environment of its parent process, except for explicit changes made by the parent when it creates the child. At the API level, these changes must be done between running 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 via  env  or using the ENVIRONMENT_VARIABLE=VALUE &lt;command&gt; notation. A running program can access the values of environment variables for configuration purposes.
  Shell scripts and batch files use environment variables to communicate data and preferences to child processes. They can also be used to store temporary values for reference later in a shell script. However, in Unix, non-exported variables are preferred for this as they don't leak outside the process.
 In Unix, an environment variable that is changed in a script or compiled program will only affect that process and possibly child processes. The parent process and any unrelated processes will not be affected. Similarly, changing or removing a variable's value inside a DOS or Windows batch file will change the variable for the duration of  COMMAND.COM or  CMD.EXE 's existence, respectively.
 In Unix, the environment variables are normally initialized during system startup by the system init startup scripts, and hence inherited by all other processes in the system. Users can, and often do, augment them in the profile script for the command shell they are using. In Microsoft Windows, each environment variable's default value is stored in the Windows Registry or set in the  AUTOEXEC.BAT  file.
 On Unix, a setuid program is given an environment chosen by its caller, but it runs with different authority from its caller. The dynamic linker will usually load code from locations specified by the environment variables $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.
 In general, the collection of environment variables function as an associative array where both the keys and values are strings. The interpretation of characters in either string differs among systems. When data structures such as lists need to be represented, it is common to use a colon (common on Unix and Unix-like) or semicolon-deliminated (common on Windows and DOS) list.
Syntax[edit]
The variables can be used both in scripts and on the command line. They are usually referenced by putting special symbols in front of or around the variable name.
 It is conventional for environment variable names to be chosen to be in all upper case. In programming code generally, this helps to distinguish environment variables from other kinds of names in the code. On Unix-like operating systems, environment variable names are case sensitive, but they are not on DOS, OS/2, and Windows.
Unix[edit]
In most Unix and Unix-like command-line shells, an environment variable's value is retrieved by placing a $ sign before the variable's name. If necessary, the name can also be surrounded by braces.
 To display the user home directory, the user may type:
If xyz needed to be appended to the value of the HOME variable, one might type:
In Unix and Unix-like systems, the names of environment variables are case-sensitive.
 The command   env   displays all environment variables and their values. The command  printenv  can also be used to print a single variable by giving that variable name as the sole argument to the command.
DOS, OS/2 and Windows[edit]
In DOS, OS/2 and Windows command-line interpreters such as COMMAND.COM and CMD.EXE, an environment variable is retrieved by placing a % sign before and after it.
 In DOS, OS/2 and Windows command-line interpreters as well as their API, upper or lower case is not distinguished for environment variable names.
 The environment variable named HOMEDRIVE contains the drive letter (plus its trailing : colon) of the user's home directory, whilst HOMEPATH contains the full path of the user's home directory within that drive.
 So to see the home drive and path, the user may type this:
 ECHO %HOMEDRIVE%%HOMEPATH%
 
The command  SET  (with no arguments) displays all environment variables and their values. set can also be used to print all variables whose name begins with a given prefix by giving the prefix as the sole argument to the command.
 In Windows PowerShell, the user may type any of the following:
 echo $env:homedrive$env:homepath
Write-Output $env:homedrive$env:homepath
"$env:homedrive$env:homepath"
 
In PowerShell, upper or lower case is not distinguished for environment variable names.
 The following command displays all environment variables and their values:
Assignment: Unix[edit]
The commands env and set can be used to set environment variables and are often incorporated directly into the shell.
 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
A few simple principles govern how environment variables achieve their effect.
 Environment variables are local to the process in which they were set. If two shell processes are spawned and the value of an environment variable is changed in one, that change will not be seen by the other.
 When a child process is created, it inherits all the environment variables and their values from the parent process. Usually, when a program calls another program, it first creates a child process by forking, then the child adjusts the environment as needed and lastly the child replaces itself with the program to be called. This procedure gives the calling program control over the environment of the called program.
 In Unix shells, variables may be assigned without the  export  keyword. Variables defined in this way are displayed by the  set  command, but are not true environment variables, as they are stored only by the shell and are unknown to all other processes. The printenv command will not display them, and child processes do not inherit them.
 VARIABLE=value
The prefix syntax exports a "true" environment variable to a child process without affecting the current process: [1] 
 VARIABLE=value program_name [arguments]
The persistence of an environment variable can be session-wide or system-wide.
   unset  is a builtin command implemented by both the Bourne shell family (sh, ksh, bash, etc.) and the C shell family (csh, tcsh, etc.) of Unix command line shells. It unsets a shell variable, removing it from memory and the shell's exported environment. It is implemented as a shell builtin, because it directly manipulates the internals of the shell. [2]   [3]  Read-only shell variables cannot be unset. If one tries to unset a read-only variable, the unset command will print an error message and return a non-zero exit code.
Assignment: DOS, OS/2 and Windows[edit]
In DOS, OS/2 and Windows command-line interpreters such as COMMAND.COM and CMD.EXE, the   SET   command is used to assign environment variables and values using the following arguments:
SET VARIABLE=value
An environment variable is removed via:
SET VARIABLE=
The  SET  command without any arguments displays all environment variables along with their values;  SET "0 or more spaces"  shows the internal ones too. In CMD.EXE, it is possible to assign local variables that do not leak outside using the  SETLOCAL  command.
 In PowerShell, the assignment follows a syntax similar to Unix:
$env:VARIABLE = "VALUE"
Examples[edit]
Examples of environment variables include:
   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 (for roaming application settings shared across multiple devices), LOCALAPPDATA (for local application settings) or PROGRAMDATA (for application settings shared between multiple OS users) should be used. [4]  
 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 shell and variants.
 MAIL (Unix-like): used to indicate where a user's mail is to be found.
 TEMP: location where processes can store temporary files. 
True environment variables[edit]
Unix[edit]
  $PATH 
Contains a colon-separated list of directories that the shell searches for commands that do not contain a slash in their name (commands with slashes are interpreted as file names to execute, and the shell attempts to execute the files directly). It is equivalent to the DOS, OS/2 and Windows  %PATH%  variable. 
  $HOME 
Contains the location of the user's home directory. Although the current user's home directory can also be found out through the C-functions getpwuid and getuid, $HOME is often used for convenience in various shell scripts (and other contexts). Using the environment variable also gives the user the possibility to point to another directory. 
  $PWD 
This variable points to the current directory. Equivalent to the output of the command pwd when called without arguments. 
  $DISPLAY 
Contains the identifier for the display that X11 programs should use by default. 
  $LD_LIBRARY_PATH 
On many Unix systems with a dynamic linker, contains a colon-separated list of directories that the dynamic linker should search for shared objects when building a process image after exec, before searching in any other directories. 
  $LIBPATH or $SHLIB_PATH 
Alternatives to $LD_LIBRARY_PATH typically used on older Unix versions. 
  $LANG, $LC_ALL, $LC_... 
 $LANG is used to set to the default locale. For example, if the locale values are pt_BR, then the language is set to (Brazilian) Portuguese and Brazilian practice is used where relevant. Different aspects of localization are controlled by individual $LC_-variables ($LC_CTYPE, $LC_COLLATE , $LC_DATE etc.). $LC_ALL can be used to force the same locale for all aspects. 
  $TZ 
Refers to time zone. It can be in several formats, either specifying the time zone itself or referencing a file (in /usr/share/zoneinfo). 
  $BROWSER 
Contains a colon-separated list of a user's web browser preferences, for use by programs that need to allow the user to view content at a URL. The browsers in the list are intended to be attempted from first to last, stopping after the first one that succeeds. This arrangement allows for fallback behavior in different environments, e.g., in an X11 environment, a graphical browser (such as Firefox) can be used, but in a console environment a terminal-base browser (such a Lynx) can be used. A %s token may be present to specify where the URL should be placed; otherwise the browser should be launched with the URL as the first argument. [5]   [6]   [7]   [8]   [9]   
DOS[edit]
Under DOS, the master environment is provided by the primary command processor, which inherits the pre-environment defined in CONFIG.SYS when first loaded. Its size can be configured through the COMMAND /E:n parameter between 160 [10]  and 32767 [10]  bytes. Local environment segments inherited to child processes are typically reduced down to the size of the contents they hold. Some command-line processors (like 4DOS) allow to define a minimum amount of free environment space that will be available when launching secondary shells. [10]  While the content of environment variables remains unchanged upon storage, their names (without the "%") are always converted to uppercase, with the exception of pre-environment variables defined via the  CONFIG.SYS  directive  SET  under DR DOS 6.0 and higher [11]   [12]  (and only with  SWITCHES=/L  (for "allow lowercase names") under DR-DOS 7.02 and higher). [10]   [13]  In principle, MS-DOS 7.0 and higher also supports lowercase variable names ( %windir% ), but provides no means for the user to define them. Environment variable names containing lowercase letters are stored in the environment just like normal environment variables, but remain invisible to most DOS software, since they are written to expect uppercase variables only. [10]   [11]   [12]  Some command processors limit the maximum length of a variable name to 80 characters. [10]  While principally only limited by the size of the environment segment, some DOS and 16-bit Windows programs [10]   [nb 1]  do not expect the contents of environment variables to exceed 128 characters. DR-DOS COMMAND.COM supports environment variables up to 255, 4DOS even up to 512 characters. [10]  Since COMMAND.COM can be configured (via /L:128..1024) to support command lines up to 1024 characters internally under MS-DOS 7.0 and higher, environment variables should be expected to contain at least 1024 characters as well. In some versions of DR-DOS, the environment passed to drivers, which often do not need their environment after installation, can be shrunken or relocated through SETENV or  INSTALL[HIGH] / LOADHIGH  options /Z (zero environment), /D[:loaddrive] (substitute drive, e.g. B:TSR.COM) and /E (relocate environment above program) in order to minimize the driver's effectively resulting resident memory footprint. [14]   [13]   [11]   [15]   [16]   [17] 
 In batch mode, non-existent environment variables are replaced by a zero-length string.
  Standard environment variables or reserved environment variables include:
  %APPEND% (supported since DOS 3.3)
This variable contains a semicolon-delimited list of directories in which to search for files. It is usually changed via the  APPEND /E command, which also ensures that the directory names are converted into uppercase. Some DOS software actually expects the names to be stored in uppercase and the length of the list not to exceed 121 [10]  characters, therefore the variable is best not modified via the  SET  command. Long filenames containing spaces or other special characters must not be quoted ("). 
  %CONFIG% (supported since MS-DOS 6.0 and PC DOS 6.1, also supported by ROM-DOS  [18] )
This variable holds the symbolic name of the currently chosen boot configuration. It is set by the DOS BIOS ( IO.SYS ,  IBMBIO.COM , etc.) to the name defined by the corresponding  CONFIG.SYS  directive  MENUITEM  before launching the primary command processor. Its main purpose is to allow further special cases in  AUTOEXEC.BAT  and similar batchjobs depending on the selected option at boot time. This can be emulated under DR-DOS by utilizing the CONFIG.SYS directive  SET  like SET CONFIG=1. 
  %CMDLINE% (introduced with 4DOS, also supported since MS-DOS 7.0)
This variable contains the fully expanded text of the currently executing command line. It can be read by applications to detect the usage of and retrieve long command lines, since the traditional method to retrieve the command line arguments through the PSP (or related API functions) is limited to 126 characters and is no longer available when FCBs get expanded or the default DTA is used. While 4DOS supports longer command lines, COMMAND.COM still only supports a maximum of 126 characters at the prompt by default (unless overridden with /U:128..255 to specify the size of the command line buffer), but nevertheless internal command lines can become longer through f.e. variable expansion (depending on /L:128..1024 to specify the size of the internal buffer). In addition to the command-line length byte in the PSP, the PSP command line is normally limited by ASCII-13, and command lines longer than 126 characters will typically be truncated by having an ASCII-13 inserted at position 127, [12]  but this cannot be relied upon in all scenarios. [12]   [nb 2]  The variable will be suppressed for external commands invoked with a preceding @-symbol like in @XCOPY ... for backward compatibility and in order to minimize the size of the environment when loading non-relocating terminate-and-stay-resident programs. Some beta versions of Windows Chicago used %CMDLINE% to store only the remainder of the command line excessing 126 characters instead of the complete command line. [11]   [12]   
   %COMSPEC%  (supported since DOS 2.0)
This variable contains the full 8.3 path to the command processor, typically C:\COMMAND.COM  or C:\DOS\COMMAND.COM. It must not contain long filenames, but under DR-DOS it may contain file and directory passwords. It is set up by the primary command processor to point to itself (typically reflecting the settings of the  CONFIG.SYS  directive  SHELL ), so that the resident portion of the command processor can reload its transient portion from disk after the execution of larger programs. The value can be changed at runtime to reflect changes in the configuration, which would require the command processor to reload itself from other locations. The variable is also used when launching secondary shells. 
  %COPYCMD% (supported since MS-DOS 6.2 and PC DOS 6.3, also supported by ROM-DOS  [18] )
Allows a user to specify the /Y switch (to assume "Yes" on queries) as the default for the  COPY ,  XCOPY , and  MOVE  commands. A default of /Y can be overridden by supplying the /-Y switch on the command line. The /Y switch instructs the command to replace existing files without prompting for confirmation. 
  %DIRCMD% (supported since MS-DOS 5.0 and PC DOS 5.0, also supported by ROM-DOS  [18] )
Allows a user to specify customized default parameters for the  DIR  command, including file specifications. Preset default switches can be overridden by providing the negative switch on the command line. For example, if %DIRCMD% contains the /W switch, then it can be overridden by using DIR /-W at the command line. This is similar to the environment variable  %$DIR%  under DOS Plus  [19]  and a facility to define default switches for DIR through its /C or /R switches under DR-DOS COMMAND.COM. [11]  %DIRCMD% is also supported by the external SDIR.COM/DIR.COM Stacker commands under Novell DOS 7 and higher. [11]   
  %LANG% (supported since MS-DOS 7.0)
This variable is supported by some tools to switch the locale for messages in multilingual issues. 
  %LANGSPEC% (supported since MS-DOS 7.0)
This variable is supported by some tools to switch the locale for messages in multilingual issues. 
  %NO_SEP% (supported since PC DOS 6.3 and DR-DOS 7.07)
This variable controls the display of thousands-separators in messages of various commands. Issued by default, they can be suppressed by specifying SET NO_SEP=ON or SET NO_SEP=1 under PC DOS. DR-DOS additionally allows to override the system's thousands-separator displayed as in f.e. SET NO_SEP=.. [10]   
   %PATH%  (supported since DOS 2.0)
This variable contains a semicolon-delimited list of directories in which the command interpreter will search for executable files. Equivalent to the Unix  $PATH  variable (but some DOS and Windows applications also use the list to search for data files similar to  $LD_LIBRARY_PATH  on Unix-like systems). It is usually changed via the  PATH  (or PATH /E under MS-DOS 6.0) command, which also ensures that the directory names are converted into uppercase. Some DOS software actually expects the names to be stored in uppercase and the length of the list not to exceed 123 [10]  characters, [nb 1]  therefore the variable should better not be modified via the  SET  command. [10]  Long filenames containing spaces or other special characters must not be quoted ("). By default, the current directory is searched first, but some command-line processors like 4DOS allow "." (for "current directory") to be included in the list as well in order to override this search order; some DOS programs are incompatible with this extension. [10]   
  %PROMPT% (supported since DOS 2.0)
This variable contains a $-tokenized string defining the display of the prompt. It is usually changed via the  PROMPT  command. 
  %TEMP% (and %TMP%)
These variables contain the path to the directory where temporary files should be stored. Operating system tools typically only use %TEMP%, whereas third-party programs also use %TMP%. Typically %TEMP% takes precedence over %TMP%. 
The DR-DOS family supports a number of additional standard environment variables including:
  %BETA% 
This variable contains an optional message displayed by some versions (including DR DOS 3.41) of COMMAND.COM at the startup of secondary shells. [20]   
  %DRDOSCFG%/%NWDOSCFG%/%OPENDOSCFG% 
This variable contains the directory [21]  (without trailing "\") where to search for .INI and .CFG configuration files (that is, DR-DOS application specific files like TASKMGR.INI, TASKMAX.INI,  VIEWMAX.INI , FASTBACK.CFG etc., class specific files like COLORS.INI, or global files like  DRDOS.INI ,  NWDOS.INI ,  OPENDOS.INI , or  DOS.INI ), as used by the INSTALL and SETUP commands and various DR-DOS programs like DISKOPT, DOSBOOK, EDIT, FBX, FILELINK, LOCK, SECURITY.OVL/NWLOGIN.EXE, SERNO, TASKMAX, TASKMGR,  VIEWMAX , or UNDELETE. [11]  It must not contain long filenames. 
  %DRCOMSPEC% 
This variable optionally holds an alternative path to the command processor taking precedence over the path defined in the %COMSPEC% variable, optionally including file and directory passwords. Alternatively, it can hold a special value of "ON" or "1" in order to enforce the usage of the %COMSPEC% variable even in scenarios where the %COMSPEC% variable may point to the wrong command-line processor, for example, when running some versions of the DR-DOS  SYS  command under a foreign operating system. [22]   
  %DRSYS% 
Setting this variable to "ON" or "1" will force some versions of the DR-DOS  SYS  command to work under foreign operating systems instead of displaying a warning. [22]   
  %FBP_USER% 
Specifies the user name used by the FastBack command  FBX  and {user}.FB  configuration files under Novell DOS 7. [11]   
  %HOMEDIR% 
This variable may contain the home directory under DR-DOS (including DR DOS 5.0 and 6.0). [11]   [20]   
  %INFO% 
In some versions of DR-DOS COMMAND.COM this variable defines the string displayed by the $I token of the  PROMPT  command. [20]  It can be used, for example, to inform the user how to exit secondary shells. 
  %LOGINNAME% 
In some versions of DR-DOS COMMAND.COM this variable defines the user name displayed by the $U token of the  PROMPT  command, as set up by f.e. login scripts for Novell NetWare. [10]   [11]   [20]  See also the similarly named pseudo-variable  %LOGIN_NAME% . 
  %MDOS_EXEC% 
This variable can take the values "ON" or "OFF" under Multiuser DOS. If enabled, the operating system permits applications to shell out to secondary shells with the DOS Program Area (DPA) freed in order to have maximum DOS memory available for secondary applications instead of running them in the same domain as under DOS. [23]   [24]   
  %NOCHAR% 
This variable can be used to define the character displayed by some commands in messages for "No" in [Y,N] queries, thereby overriding the current system default (typically "N" in English versions of DR-DOS). If it contains a string, only the first character, uppercased, will be taken. Some commands also support a command line parameter /Y to automatically assume "Yes" on queries, thereby suppressing such prompts. If, however, the parameter /Y:yn is used to specify the "Yes"/"No" characters (thereby overriding any %NOCHAR% setting), queries are not suppressed. See also the related CONFIG.SYS directive  NOCHAR  and the environment variable  %YESCHAR% . [22]   
  %NOSOUND% 
Setting this variable to "ON" or "1" will disable default beeps issued by some DR-DOS commands in certain situations such as to inform the user of the completion of some operation, that user interaction is required, or when a wrong key was pressed. Command line options to specifically enable certain beeps will override this setting. 
  %OS% 
This variable contains the name of the operating system in order to distinguish between different DOS-related operating systems of Digital Research-origin in batch jobs and applications. [21]  Known values include "DOSPLUS" (DOS Plus 1.2 in DOS emulation), "CPCDOS 4.1" (DOS Plus 1.2 in CP/M emulation), "DRDOS" (DR DOS 3.31-6.0, DR DOS Panther, DR DOS StarTrek, DR-DOS 7.02  [21] -7.05), "EZDOS" (EZ-DOS 3.41), "PALMDOS" and "NetWare PalmDOS" (PalmDOS 1.0), "NWDOS" (Novell DOS 7), "NWDOS7" (Novell DOS 7 Beta), "OPENDOS" (Caldera OpenDOS 7.01, Caldera DR-OpenDOS 7.02), "CDOS" (Concurrent DOS, Concurrent DOS XM), "CPCDOS" (Concurrent PC DOS), "CDOS386" (Concurrent DOS 386), "DRMDOS" (DR Multiuser DOS), "MDOS" (CCI Multiuser DOS), [23]  "IMSMDOS" (IMS Multiuser DOS), "REAL32" (REAL/32). [11]   [25]  MS-DOS  INTERSVR  looks for a value of "DRDOS" as well. [25]  See also the identically named environment variable  %OS%  later introduced in the Windows NT family. 
  %PEXEC% 
In some versions of DR-DOS this variable defines the command executed by the $X token of the  PROMPT  command before COMMAND.COM displays the prompt after returning from external program execution. [11]   [21]   
  %SWITCHAR% 
This variable defines the SwitChar to be used for argument parsing by some DR-DOS commands. If defined, it overrides the system's current SwitChar setting. The only accepted characters are "/" (DOS style), "-" (Unix style) and "[" (CP/M style). See also the related CONFIG.SYS directive  SWITCHAR  (to set the system's SwitChar setting) and the  %/%  system information variable in some issues of DR-DOS COMMAND.COM (to retrieve the current setting for portable batchjobs). 
  %TASKMGRWINDIR% 
This variable specifies the directory, where the Windows  SYSTEM.INI  to be used by the DR-DOS TASKMGR multitasker is located, overriding the default procedure to locate the file. [11]   
  %VER% 
This variable contains the version of the operating system in order to distinguish between different versions of DR-DOS in batch jobs and in the display of the  VER  command. [21]  It is also used for the $V token of the  PROMPT  command and affects the value returned by the system information variable  %OS_VERSION% . Known values include "1.0" (PalmDOS 1.0), "1.2" (DOS Plus 1.2 in DOS emulation), "2.0" (Concurrent DOS 386 2.0), "3.0" (Concurrent DOS 386 3.0), "3.31" (DR DOS 3.31), "3.32" (DR DOS 3.32), "3.33" (DR DOS 3.33), "3.34" (DR DOS 3.34), "3.35" (DR DOS 3.35), "3.40" (DR DOS 3.40), "3.41" (DR DOS 3.41, EZ-DOS 3.41), "3.41T" (DR DOS 3.41T), "4.1" (Concurrent PC DOS 4.1), "5.0" (DR DOS 5.0, DR Multiuser DOS 5.0), "5.1" (Novell DR Multiuser DOS 5.1), "6.0" (DR Concurrent DOS XM 6.0, DR DOS 6.0), "6.2" (DR Concurrent DOS XM 6.2), "7" (Novell DOS 7, Caldera OpenDOS 7.01, DR-DOS 7.02-7.05), "7.00" (CCI Multiuser DOS 7.00), "7.07" (DR-DOS 7.07), "7.1" (IMS Multiuser DOS 7.1), "7.21" (CCI Multiuser DOS 7.21), [23]  "7.22" (CCI Multiuser DOS 7.22) etc. [11]   [25]   [23]   
  %YESCHAR% 
This variable can be used to define the character displayed by some commands in messages for "Yes" in [Y,N] queries, thereby overriding the current system default (typically "Y" in English versions of DR-DOS). If it contains a string, only the first character, uppercased, will be taken. Some commands also support a command line parameter /Y to automatically assume "Yes" on queries, thereby suppressing such prompts. If, however, the parameter /Y:y is used to specify the "Yes" character (thereby overriding any %YESCHAR% setting), queries are not suppressed. See also the related CONFIG.SYS directive  YESCHAR  and the environment variable  %NOCHAR% . [22]   
  %$CLS% 
This variable defines the control sequence to be sent to the console driver to clear the screen when the  CLS  command is issued, thereby overriding the internal default ("←[2J" under DR-DOS, "←E" under DOS Plus 1.2 on Amstrad machines [19]  as well as under Concurrent DOS, Multiuser DOS, and REAL/32 for VT52 terminals, or "←+" under Multiuser DOS for ASCII terminals). [23]  If the variable is not defined and no  ANSI.SYS  console driver is detected, the DR-DOS COMMAND.COM will directly clear the screen via INT 10h/AH=00h BIOS function, like MS-DOS/PC DOS COMMAND.COM does. A special \nnn-notation for octal numbers is supported to allow the definition of special characters like ESC (ASCII-27 = "←" = 1Bh = 33o), as f.e. in SET $CLS=\033[2J. To send the backslash ("\") itself, it can be doubled "\\". [11]   [20]   [23]   
  %$DIR% 
Supported by DOS Plus accepting the values "L" (long) or "W" (wide) to change the default layout of directory listings with DIR. Can be overridden using the command line options /L or /W. [20]   [19]  See also the similar environment variable  %DIRCMD%  and the DIR options /C and /R of the DR-DOS COMMAND.COM. [11]   
  %$PAGE% 
Supported by DOS Plus accepting the values "ON" or "OFF" for pagination control. Setting this to "ON" has the same affect as adding /P to commands supporting it (like DIR or TYPE). [20]   [19]   
  %$LENGTH% 
Used by DOS Plus to define the screen length of the console in lines. This is used to control in a portable way when the screen output should be temporarily halted until a key is pressed in conjunction with the /P option supported by various commands or with automatic pagnination. [20]   [19]  See also the related environment variables  %$WIDTH%  and  %DIRSIZE%  as well as the similar pseudo-variable  %_ROWS% . 
  %$WIDTH% 
Used by DOS Plus to define the screen width of the console in columns. This is used to control in a portable way the formatting of the screen output of commands like  DIR /W or  TYPE filename. [20]   [19]  See also the related environment variables  %$LENGTH%  and  %DIRSIZE%  as well as the similar pseudo-variable  %_COLUMNS% . 
  %$SLICE% 
Used by DOS Plus accepting a numerical value to control the foreground/background time slicing of multitasking programs. [20]   [19]  See also the DOS Plus command  SLICE . 
  %$ON% 
This variable can hold an optional control sequence to switch text highlighting, reversion or colorization on. It is used to emphasize or otherwise control the display of the file names in commands like  TYPE wildcard, for example SET $ON=\033[1m with ANSI.SYS loaded or SET $ON=\016 for an IBM or ESC/P printer. For the special \nnn octal notation supported, see  %$CLS% . [11]   [19]  While the variable is undefined by default under DOS Plus and DR-DOS, the Multiuser DOS default for an ASCII terminal equals SET $ON=\033p. [20]   [23]  See also the related environment variable  %$OFF% . 
  %$OFF% 
This variable can hold an optional control sequence to switch text highlighting, reversion or colorization off. It is used to return to the normal output after the display of file names in commands like  TYPE wildcard, for example SET $OFF=\033[0m with ANSI.SYS loaded or SET $OFF=\024 for an IBM or ESC/P printer. For the special \nnn octal notation supported, see  %$CLS% . [11]   [19]  While the variable is undefined by default under DOS Plus and DR-DOS, the Multiuser DOS default for an ASCII terminal equals SET $OFF=\033q. [20]   [23]  See also the related environment variable  %$ON% . 
  %$HEADER% 
This variable can hold an optional control sequence issued before the output of the file contents in commands like  TYPE  under DR-DOS 7.02 and higher. It can be used for highlighting, pagination or formatting, f.e. when sending the output to a printer, i.e. SET $HEADER=\017 for an IBM or ESC/P printer. For the special \nnn octal notation supported, see  %$CLS% . [20]  See also the related environment variable  %$FOOTER% . 
  %$FOOTER% 
This variable can hold an optional control sequence issued after the output of the file contents in commands like  TYPE  under DR-DOS 7.02 and higher. It is used to return to the normal output format, i.e. SET $FOOTER=\022\014 in the printer example above. For the special \nnn octal notation supported, see  %$CLS% . [20]  See also the related environment variable  %$HEADER% . 
 Datalight ROM-DOS supports a number of additional standard environment variables as well including:
  %DIRSIZE% 
This variable is used to define non-standard screen sizes rows[,cols] for  DIR  options /P and /W (similar to  %$LENGTH%  and  %$WIDTH%  under DOS Plus). [18]   
  %NEWFILE% 
This variable is automatically set to the first parameter given to the CONFIG.SYS directive NEWFILE. [18]   
 %TZ%, %COMM%, %SOCKETS%, %HTTP_DIR%, %HOSTNAME% and %FTPDIR% are also used by ROM-DOS. [18] 
OS/2[edit]
  %BEGINLIBPATH% 
Contains a semicolon-separated list of directories which are searched for DLLs before the directories given by the  %LIBPATH%  variable (which is set during system startup with the special CONFIG.SYS directive  LIBPATH ). It is possible to specify relative directories here, including "." for the current working directory. See also the related environment variable  %ENDLIBPATH% . 
  %ENDLIBPATH% 
a list of directories to be searched for DLLs like  %BEGINLIBPATH% , but searched after the list of directories in  %LIBPATH% . 
Windows[edit]
 System path variables [ citation needed ] refer to locations of critical operating system resources, and as such generally are not user-dependent.
  %APPDATA% 
Contains the full path to the  Application Data  directory of the logged-in user. Does not work on Windows NT 4.0 SP6 UK. 
  %LOCALAPPDATA% 
This variable is the temporary files of Applications. Its uses include storing of desktop themes, Windows error reporting, caching and profiles of web browsers. 
  %ComSpec%/%COMSPEC% 
The %ComSpec% variable contains the full path to the command processor; on the Windows NT family of operating systems, this is cmd.exe, while on Windows 9x, %COMSPEC% is COMMAND.COM. 
  %OS% 
The %OS% variable contains a symbolic name of the operating system family to distinguish between differing feature sets in batchjobs. It resembles an identically named environment variable  %OS%  found in all DOS-related operating systems of Digital Research-origin like Concurrent DOS, Multiuser DOS, REAL/32, DOS Plus, DR DOS, Novell DOS and OpenDOS. %OS% always holds the string "Windows_NT" on the Windows NT family. [26]   
  %PATH% 
This variable contains a semicolon-delimited (do not put spaces in between) list of directories in which the command interpreter will search for an executable file that matches the given command. Environment variables that represent paths may be nested within the %PATH% variable, but only at one level of indirection. If this sub-path environment variable itself contains an environment variable representing a path, %PATH% will not expand properly in the variable substitution. Equivalent to the Unix  $PATH  variable. 
  %ProgramFiles%, %ProgramFiles(x86)%, %ProgramW6432% 
The %ProgramFiles% variable points to the Program Files directory, which stores all the installed programs of Windows and others. The default on English-language systems is "C:\Program Files". In 64-bit editions of Windows (XP, 2003, Vista), there are also %ProgramFiles(x86)%, which defaults to "C:\Program Files (x86)", and %ProgramW6432%, which defaults to "C:\Program Files". The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit (this is caused by Windows-on-Windows 64-bit redirection). 
  %CommonProgramFiles% 
This variable points to the Common Files directory. The default is "C:\Program Files\Common Files" in the English version of Windows. 
  %OneDrive% 
The %OneDrive% variable is a special system-wide environment variable found on Windows NT and its derivatives. Its value is the path of where (if installed and setup) the Onedrive directory is located. The value of %OneDrive% is in most cases "C:\Users\{Username}\OneDrive\". 
  %SystemDrive% 
The %SystemDrive% variable is a special system-wide environment variable found on Windows NT and its derivatives. Its value is the drive upon which the system directory was placed. The value of %SystemDrive% is in most cases "C:". 
  %SystemRoot% 
The %SystemRoot% variable is a special system-wide environment variable found on the Windows NT family of operating systems. Its value is the location of the system directory, including the drive and path. The drive is the same as %SystemDrive% and the default path on a clean installation depends upon the version of the operating system. By default:
  Windows XP and newer versions use "\WINDOWS".
 Windows 2000, NT 4.0 and NT 3.1 use "\WINNT".
 Windows NT 3.5 and NT 3.51 uses "\WINNT35".
 Windows NT 4.0 Terminal Server uses "\WTSRV".   
  %windir% 
This variable points to the Windows directory. (On the Windows NT family of operating systems, it is identical to the %SystemRoot% variable). Windows 95–98 and Windows ME are, by default, installed in "C:\Windows". For other versions of Windows, see the %SystemRoot% entry above. 
 User management variables [ citation needed ] store information related to resources and settings owned by various user profiles within the system. As a general rule, these variables do not refer to critical system resources or locations that are necessary for the OS to run.
  %ALLUSERSPROFILE% (%PROGRAMDATA% since Windows Vista)
This variable expands to the full path to the All Users profile directory. This profile contains resources and settings that are used by all system accounts. Shortcut links copied to the All Users\' Start menu or Desktop directories will appear in every user's Start menu or  Desktop , respectively. 
  %USERDOMAIN% 
The name of the  Workgroup  or  Windows Domain  to which the current user belongs. The related variable, %LOGONSERVER%, holds the hostname of the server that authenticated the current user's login credentials (name and password). For home PCs and PCs in a workgroup, the authenticating server is usually the PC itself. For PCs in a Windows domain, the authenticating server is a domain controller (a primary domain controller, or PDC, in Windows NT 4-based domains). 
  %USERPROFILE% 
A special system-wide environment variable found on Windows NT and its derivatives. Its value is the location of the current user's profile directory, in which is found that user's HKCU registry hive (NTUSER). Users can also use the %USERNAME% variable to determine the active users login identification. 
 Optional System variables [ citation needed ] are not explicitly specified by default but can be used to modify the default behavior of certain built-in console commands. These variables also do not need to be explicitly specified as command line arguments.
Default values[edit]
The following tables shows typical default values of certain environment variables under English versions of Windows as they can be retrieved under  CMD .
 (Some of these variables are also defined when running COMMAND.COM under Windows, but differ in certain important details: Under COMMAND.COM, the names of environment variable are always uppercased. Some, but not all variables contain short 8.3 rather than long file names. While some variables present in the CMD environment are missing, there are also some variables specific to the COMMAND environment.)
 
Variable
Locale specific
Windows XP (CMD)
Windows Vista and later (CMD)
 
%ALLUSERSPROFILE% [27] 
Yes
C:\Documents and Settings\All Users
C:\ProgramData [27] 
 
%APPDATA% [27] 
Yes
C:\Documents and Settings\{username}\Application Data
C:\Users\{username}\AppData\Roaming [27] 
 
%CommonProgramFiles% [27] 
Yes
C:\Program Files\Common Files
C:\Program Files\Common Files [27] 
 
%CommonProgramFiles(x86)% [27] 
Yes
C:\Program Files (x86)\Common Files (only in 64-bit version)
C:\Program Files (x86)\Common Files (only in 64-bit version)  [27] 
 
%CommonProgramW6432% [27] 
Yes
%CommonProgramW6432% (not supported, not replaced by any value)
C:\Program Files\Common Files (only in 64-bit version)  [27] 
 
%COMPUTERNAME%
No
{computername}
{computername}
 
%ComSpec%
No
C:\Windows\System32\cmd.exe
C:\Windows\System32\cmd.exe
 
%HOMEDRIVE% [27] 
No
C:
C: [27] 
 
%HOMEPATH% [27] 
Yes
\Documents and Settings\{username}
\Users\{username} [27] 
 
%LOCALAPPDATA% [27] 
Yes
%LOCALAPPDATA% (not supported, not replaced by any value)
C:\Users\{username}\AppData\Local [27] 
 
%LOGONSERVER%
No
\\{domain_logon_server}
\\{domain_logon_server}
 
%PATH%
Yes
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths}
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths}
 
%PATHEXT%
No
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.WSF;.WSH
.com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc
 
%ProgramData% [27] 
Yes
%ProgramData% (not supported, not replaced by any value)
%SystemDrive%\ProgramData [27] 
 
%ProgramFiles% [27] 
Yes
%SystemDrive%\Program Files
%SystemDrive%\Program Files [27] 
 
%ProgramFiles(x86)% [27] 
Yes
%SystemDrive%\Program Files (x86) (only in 64-bit version)
%SystemDrive%\Program Files (x86) (only in 64-bit version)  [27] 
 
%ProgramW6432% [27] 
Yes
%ProgramW6432% (not supported, not replaced by any value)
%SystemDrive%\Program Files (only in 64-bit version)  [27] 
 
%PROMPT%
No
Code for current command prompt format, usually $P$G
Code for current command prompt format, usually $P$G
 
%PSModulePath%
%PSModulePath% (not supported, not replaced by any value)
%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\
 
%PUBLIC% [27] 
Yes
%PUBLIC% (not supported, not replaced by any value)
%SystemDrive%\Users\Public [27] 
 
%SystemDrive% [27] 
No
C:
C: [27] 
 
%SystemRoot% [27] 
No
The Windows directory, usually C:\Windows, formerly C:\WINNT
%SystemDrive%\Windows [27] 
 
%TEMP% [27]  and %TMP% [27] 
Yes
%SystemDrive%\Documents and Settings\{username}\Local Settings\Temp
%SystemRoot%\TEMP (for system environment variables %TMP% and %TEMP%), %USERPROFILE%\AppData\Local\Temp [27]  (for user environment variables %TMP% and %TEMP%)
 
%USERDOMAIN%
No
{userdomain}
{userdomain}
 
%USERNAME%
No
{username}
{username}
 
%USERPROFILE% [27] 
Yes
%SystemDrive%\Documents and Settings\{username}
%SystemDrive%\Users\{username} [27] 
 
%windir% [27] 
No
%SystemDrive%\WINDOWS
%SystemDrive%\Windows [27] 
   
In this list, there is no environment variable that refers to the location of the user's My Documents directory, so there is no standard method for setting a program's home directory to be the My Documents directory.
Pseudo-environment variables[edit]
The command processors in DOS and Windows also support pseudo-environment variables. These are values that are fetched like environment variables, but are not truly stored in the environment but computed when requested.
DOS[edit]
Besides true environment variables, which are statically stored in the environment until changed or deleted, a number of pseudo-environment variables exist for batch processing.
 The so-called replacement parameters or replaceable parameters (Microsoft / IBM terminology) aka replacement variables (Digital Research / Novell / Caldera terminology) [21]  or  batch file parameters  (JP Software terminology) [10]  %1..%9 and %0 can be used to retrieve the calling parameters of a batchjob, see  SHIFT . In batchjobs, they can be retrieved just like environment variables, but are not actually stored in the environment.
 
Some command-line processors (like DR-DOS COMMAND.COM, [21]  Multiuser DOS MDOS.COM/ TMP.EXE  (Terminal Message Process), JP Software 4DOS, 4OS2, 4NT, Take Command and Windows cmd.exe) support a type of pseudo-environment variables named system information variables (Novell / Caldera terminology) [21]  or internal variables (JP Software terminology), [10]  which can be used to retrieve various possibly dynamic, but read-only information about the running system in batch jobs. The returned values represent the status of the system in the moment these variables are queried; that is, reading them multiple times in a row may return different values even within the same command; querying them has no direct effect on the system. Since they are not stored in the environment, they are not listed by SET and do not exist for external programs to retrieve. If a true environment variable of the same name is defined, it takes precedence over the corresponding variable until the environment variable is deleted again. They are not case-sensitive.
While almost all such variables are prefixed with an underscore ("_") by 4DOS etc. by convention (f.e.  %_SECOND% ), [10]  they are not under DR-DOS COMMAND.COM (f.e.  %OS_VERSION% ).
 In addition, 4DOS, 4OS2, 4NT, and Take Command also support so called variable functions, [10]  including user-definable ones. They work just like internal variables, but can take optional parameters (f.e. %@EVAL[]%) and may even change the system status depending on their function.
  System information variables supported by DR-DOS COMMAND.COM:
  %AM_PM% 
This pseudo-variable returns the ante- or post-midday status of the current time. The returned string depends on the locale-specific version of DR-DOS, f.e. "am" or "pm" in the English version. It resembles an identically named identifier variable in Novell NetWare login scripts. 
  %DAY% 
This pseudo-variable returns the days of the current date in a 2-digit format with leading zeros, f.e. "01".."31". See also the similar pseudo-variable  %_DAY% . It resembles an identically named identifier variable in Novell NetWare login scripts. 
  %DAY_OF_WEEK% 
This pseudo-variable returns the day name of the week in a 3-character format. The returned string depends on the locale-specific version of DR-DOS, f.e. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", or "Sat" in the English version. It resembles an identically named identifier variable in Novell NetWare login scripts. 
  %ERRORLEVEL% 
In COMMAND.COM of DR-DOS 7.02 and higher, this pseudo-variable returns the last error level returned by an external program or the  RETURN  command, f.e. "0".."255". [28]   [29]  See also the identically named pseudo-variable  %ERRORLEVEL%  under Windows and the  IF ERRORLEVEL  conditional command. 
  %ERRORLVL% 
In DR-DOS 7.02 and higher, this pseudo-variable returns the last error level in a 3-digit format with leading zeros, f.e. "000".."255". [28]   [29]  Under Multiuser DOS, this is a true environment variable automatically updated by the shell to the return code of exiting programs. [23]  See also the related pseudo-variable  %ERRORLEVEL%  under DR-DOS and the  IF ERRORLEVEL  command. 
  %GREETING_TIME% 
This pseudo-variable returns the 3-level day greeting time. The returned string depends on the locale-specific version of DR-DOS, f.e. "morning", "afternoon", or "evening" in the English version. It resembles an identically named identifier variable in Novell NetWare login scripts. 
  %HOUR% 
This pseudo-variable returns the hours of the current time in 12-hour format without leading zeros, f.e. "1".."12". It resembles an identically named identifier variable in Novell NetWare login scripts. 
  %HOUR24% 
This pseudo-variable returns the hours of the current time in 24-hour format in a 2-digit format with leading zeros, f.e. "00".."23". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable  %_HOUR% . 
  %MINUTE% 
This pseudo-variable returns the minutes of the current time in a 2-digit format with leading zeros, f.e "00".."59". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable  %_MINUTE% . 
  %MONTH% 
This pseudo-variable returns the months of the current date in a 2-digit format with leading zeros, f.e. "01".."12". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable  %_MONTH% . 
  %MONTH_NAME% 
This pseudo-variable returns the month name of the current date. The returned string depends on the locale-specific version of DR-DOS, f.e. "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", or "December" in the English version. It resembles an identically named identifier variable in Novell NetWare login scripts. 
  %NDAY_OF_WEEK% 
This pseudo-variable returns the number of day of the current week, f.e. "1".."7" (with "1" for Sunday). It resembles an identically named identifier variable in Novell NetWare login scripts. 
  %OS_VERSION% 
This pseudo-variable returns the version of the operating system depending on the current setting of the environment variable  %VER% . If %VER% is not defined, %OS_VERSION% returns "off". It resembles an identically named identifier variable in Novell NetWare login scripts, which may return versions also for non-DR-DOS versions of DOS. 
  %SECOND% 
This pseudo-variable returns the seconds of the current time in a 2-digit format with leading zeros, f.e. "00".."59". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable  %_SECOND% . 
  %SHORT_YEAR% 
This pseudo-variable returns the year of the current date in a 2-digit format with leading zeros, f.e. "93".."99", "00".."92". It resembles an identically named identifier variable in Novell NetWare login scripts. 
  %YEAR% and %_YEAR% 
Supported since Novell DOS 7, the %YEAR% pseudo-variable returns the year of the current date in a 4-digit format, f.e. "1980".."2099". It resembles an identically named identifier variable in Novell NetWare login scripts. DR-DOS 7.02 and higher added %_YEAR% for compatibility with 4DOS, returning the same value. [10]   
  %/% 
In COMMAND.COM of DR-DOS 7.02 and higher, this pseudo-variable returns the current SwitChar setting of the system, either "/" (DOS style) or "-" (Unix style). [30]   [31]  See also the related CONFIG.SYS directive SWITCHAR and the environment variable  %SWITCHAR% . 
  %_CODEPAGE% 
This pseudo-variable returns the systems' current code page ("1".."65533"), f.e. " 437 ", " 850 ", " 858 ". This variable was originally introduced by 4DOS, [10]  but also became available with COMMAND.COM since DR-DOS 7.02. See also the  CHCP  command. 
  %_COLUMNS% 
This pseudo-variable returns the current number of screen columns depending on the display mode, f.e. "40", "80", "132", etc. This variable was originally introduced by 4DOS, [10]  but also became available with COMMAND.COM since DR-DOS 7.02. See also a similar environment variable  %$WIDTH%  under DOS Plus. 
  %_COUNTRY% 
This pseudo-variable returns the systems' current country code ("1".."65534"), f.e. "1" for USA, "44" for UK, "49" for Germany, "20049" with ISO 8601, "21049" with ISO 8601 and Euro support. [31]   [32]  This variable was originally introduced by 4DOS, [10]  but also became available with COMMAND.COM since DR-DOS 7.02. See also the CONFIG.SYS directive  COUNTRY . 
  %_DAY% 
This pseudo-variable returns the days of the current date without leading zeros, f.e. "1".."31". This variable was originally introduced by 4DOS, [10]  but also became available with COMMAND.COM since DR-DOS 7.02. See also the similar pseudo-variable  %DAY% . 
  %_HOUR% 
This pseudo-variable returns the hours of the current time in 24-hour format without leading zeros, f.e. "0".."23". This variable was originally introduced by 4DOS, [10]  but also became available with COMMAND.COM since DR-DOS 7.02. See also the similar pseudo-variable  %HOUR24% . 
  %_MINUTE% 
This pseudo-variable returns the minutes of the current time without leading zeros, f.e "0".."59". This variable was originally introduced by 4DOS, [10]  but also became available with COMMAND.COM since DR-DOS 7.02. See also the similar pseudo-variable  %MINUTE% . 
  %_MONTH% 
This pseudo-variable returns the months of the current date without leading zeros, f.e. "1".."12". This variable was originally introduced by 4DOS, [10]  but also became available with COMMAND.COM since DR-DOS 7.02. See also the similar pseudo-variable  %MONTH% . 
  %_ROWS% 
This pseudo-variable returns the current number of screen rows depending on the display mode, f.e. "25", "43", "50", etc. This variable was originally introduced by 4DOS, [10]  but also became available with COMMAND.COM since DR-DOS 7.02. See a similar environment variable  %$LENGTH%  under DOS Plus. 
  %_SECOND% 
This pseudo-variable returns the seconds of the current time without leading zeros, f.e. "0".."59". This variable was originally introduced by 4DOS, [10]  but also became available with COMMAND.COM since DR-DOS 7.02. See also the similar pseudo-variable  %SECOND% . 
 System information variables supported by DR-DOS COMMAND.COM with networking loaded:
  %LOGIN_NAME% 
This pseudo-variable returns the user name. This always worked with  NETX , but it will also work with Personal NetWare's ODI/VLM if the current drive is a PNW-mapped drive (otherwise an empty string is returned). See also the similarly named environment variable  %LOGINNAME% . 
  %P_STATION% 
This pseudo-variable returns the physical station number in a format "????????????". The value depends on the MAC address of the network adapter, but can be overridden. It resembles an identically named identifier variable in Novell NetWare login scripts. 
  %STATION% 
This pseudo-variable returns the logical station number starting with "1" for the first client. The numbers are assigned by the file server and remain static for as long as the IPX connection remains established. It resembles an identically named identifier variable in Novell NetWare login scripts. 
  %FULL_NAME% 
This pseudo-variable returns the full name of the logged in user, if available. It resembles an identically named identifier variable in Novell NetWare login scripts. See also the related pseudo-variable  %LOGIN_NAME% . 
Windows[edit]
 Dynamic environment variables (also named internal variables or system information variables under DOS) are pseudo-environment variables supported by  CMD.EXE  when command-line extensions are enabled, and they expand to various discrete values whenever queried, that is, their values can change when queried multiple times even within the same command. While they can be used in batch jobs and at the prompt, they are not stored in the environment. Consequently, they are neither listed by SET nor do they exist for external programs to read. They are not case-sensitive.
 Indirectly, they are also supported under Windows' COMMAND.COM, which has been modified to internally call CMD.EXE to execute the commands.
  %CD% 
This pseudo-variable expands to the current directory equivalent to the output of the command  CD  when called without arguments. While a long filename can be returned under CMD.EXE depending on the current directory, the fact that the current directory will always be in 8.3 format under COMMAND.COM will cause it to return a short filename under COMMAND.COM, even when COMMAND internally calls CMD. 
  %CMDCMDLINE% 
This pseudo-variable expands to the original startup parameters of  CMD.EXE , f.e. "C:\Windows\system32\cmd.exe". Under Windows' COMMAND.COM, this may return something like "C:\Windows\system32\cmd.exe /c ..." due to the fact that COMMAND.COM calls CMD.EXE internally. 
  %CMDEXTVERSION% 
This pseudo-variable expands to the version of the command-line extensions of  CMD.EXE , if enabled (e.g. "1" under Windows NT, "2" under Windows 2000 and Windows XP). 
  %DATE% 
This pseudo-variable expands to the current date. The date is displayed according to the current user's date format preferences. 
  %ERRORLEVEL% 
This pseudo-variable expands to the last set error level, a value between "0" and "255" (without leading zeros). [28]   [33]   [29]  External commands and some internal commands set error levels upon execution. See also the identically named pseudo-variable  %ERRORLEVEL%  under DR-DOS and the  IF ERRORLEVEL  command. 
  %HIGHESTNUMANODENUMBER% 
This pseudo-variable returns the number of the highest NUMA node. 
  %RANDOM% 
This pseudo-variable returns a random number between "0" and "32767". 
  %TIME% 
This pseudo-variable returns the current time. The time is displayed according to the current user's time format preferences. If the %TIME% and  %DATE%  variables are both used, it is important to read them both in this particular order in rapid succession in order to avoid midnight-rollover problems. 
Other shells[edit]
Unix-like shells have similar dynamically generated variables, bash's $RANDOM being a well-known example. However, since these shells have a concept of local variables, they are described as special local variables instead. [34] 
See also[edit]
  Variable (computer science) 
 List of Unix commands 
 List of DOS commands 
 Special folder 
 Modules Environment 
 PWB shell 
 Windows Registry  
Notes[edit]
 
^    a       b    Applications not coping properly with environment variables longer than 128 characters include CadStar PCB, Checkit, Computer Select CD-ROM, RenderMan, VINES Network, Windows 3.0, and Word for Windows 6.0.
  ^  4DOS and MS-DOS 7.0 set the length to 127 and insert ASCII-13 at this position, but Borland libraries set the length to the invalid value of 128 and do not insert an ASCII-13. For shorter command lines, 4DOS/NDOS and DR-DOS also insert an ASCII-0 after the ASCII-13, but not when invoked vis INSTALL directive; MS-DOS doesn't.
 
References[edit]
 
  ^  Robbins, Arnold; Beebe, Nelson H. F. (May 2005). Apandi, Tatiana; Randal, Allison; Witwer, Adam (eds.). Classic Shell Scripting (1 ed.). O'Reilly. ISBN  978-0-596-00595-5 .
  ^   "unset - unset values and attributes of variables and functions – ". Commands &amp; Utilities Reference, The Single UNIX Specification - The Open Group Base Specifications, IEEE Std 1003.1-2008 (Issue 7 ed.). The IEEE and The Open Group. 2016 [2001]. Archived from the original on 2017-12-18. Retrieved 2017-12-18.
  ^  fgrose (2015-07-31) [2011]. "The unset builtin command". Bash Hackers Wiki. Archived from the original on 2017-12-18. Retrieved 2017-12-18.
  ^  Jacobs, Mike; Koren, Alexander; Satran, Michael (2017-11-14). "Store and retrieve settings and other app data". Microsoft. Archived from the original on 2017-12-18. Retrieved 2017-12-18.
  ^   Raymond, Eric (2002-08-02) [Originally published 2001]. "The BROWSER project". Archived from the original on 2019-09-21. Retrieved 2020-10-21.
  ^   "LWN - Development". LWN.net. 2001-02-01. Archived from the original on 2019-02-08. Retrieved 2020-10-21. Standardizing a BROWSER environment variable. Eric Raymond is promoting the use of a new environment variable, BROWSER, to complement the existing PAGER, MAILER, and EDITOR variables. This effort is being tested as an experiment in hacking social systems. 
  ^  Špaček, Michal (2020-01-19) [First version published 2013]. "Env::Browser-0.06". metacpan.org. Archived from the original on 2020-10-21. Retrieved 2020-10-21. Env::Browser - Process environment variable $BROWSER and run web browser 
  ^   "webbrowser — Convenient Web-browser controller". docs.python.org. Archived from the original on 2020-10-13. Retrieved 2020-10-21.
  ^   "DefaultWebBrowser - Debian Wiki". wiki.debian.org. 2020-06-10. Archived from the original on 2020-10-21. Retrieved 2020-10-21. The environment variable BROWSER can be set to[…] always choose your desired browser. 
^    a       b       c       d       e       f       g       h       i       j       k       l       m       n       o       p       q       r       s       t       u       v       w       x       y       z       aa       ab    Brothers, Hardin; Rawson, Tom; Conn, Rex C.; Paul, Matthias R.; Dye, Charles E.; Georgiev, Luchezar I. (2002-02-27).  4DOS 8.00 online help .
^    a       b       c       d       e       f       g       h       i       j       k       l       m       n       o       p       q       r    Paul, Matthias R. (1997-07-30) [1994-05-01].  NWDOS-TIPs — Tips &amp; Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds . MPDOSTIP. Release 157 (in German) (3 ed.). Archived from the original on 2016-11-04. Retrieved 2014-08-06. (NB. NWDOSTIP.TXT is a comprehensive work on Novell DOS 7 and OpenDOS 7.01, including the description of many undocumented features and internals. The provided link points to a HTML-converted version of the file, which is part of the MPDOSTIP.ZIP collection.) [1]
^    a       b       c       d       e    Paul, Matthias R. (1997-05-01) [1995-03-01]. "Hinweise zu JPSofts 4DOS 5.5b/c, 5.51, 5.52a und NDOS". MPDOSTIP (in German). Archived from the original on 2016-11-04. Retrieved 2015-05-08. (NB. The provided link points to a HTML-converted version of the 4DOS5TIP.TXT file, which is part of the MPDOSTIP.ZIP collection.) [2]
^    a       b    Paul, Matthias R. (1997-10-02). "Caldera OpenDOS 7.01/7.02 Update Alpha 3 IBMBIO.COM README.TXT". Archived from the original on 2003-10-04. Retrieved 2009-03-29. [3]
  ^  Paul, Matthias R. (1997-05-27) [1996]. "SETENV v1.11". Archived from the original on 2009-02-15. Retrieved 2019-08-09. […] SETENV […] to hide and later restore the […] pre-environment […] By using SETENV.COM you can save some KiloBytes of rare DOS memory […] depending on the number of drivers loaded by INSTALL=/INSTALLHIGH=/HIINSTALL= and the current size of the pre-environment. […] this original […] feature cannot be found in any known memory manager/optimizer. […] 
  ^  Paul, Matthias R. (2002-04-06). "Re: [fd-dev] ANNOUNCE: CuteMouse 2.0 alpha 1". freedos-dev. Archived from the original on 2020-02-07. Retrieved 2020-02-07. […] In CTMOUSE.ASM prepareTSR routine I found a comment in regard to the zero-environment. […] DESQview or DRDOS zero-env? […] release environment block […] skip if any problem […] zero-pad for MEM style utilities […] 
  ^   "PTS-DOS 2000 Pro User Manual" (PDF). Archived (PDF) from the original on 2018-05-12. Retrieved 2018-05-12.
  ^  Paul, Matthias R. (2002-10-07). "Re: Run a COM file". Newsgroup: alt.msdos.programmer. Archived from the original on 2017-09-03. Retrieved 2017-09-03. [4]
^    a       b       c       d       e       f     Datalight, Inc.; GPvNO (April 2005) [1999]. "Datalight ROM-DOS User's Guide" (PDF). Datalight, Inc. 3010-0200-0716. Archived (PDF) from the original on 2019-03-20. Retrieved 2018-09-16.
^    a       b       c       d       e       f       g       h       i     Kotulla, Martin (November 1987). "Von CP/M zu MS-DOS, Teil 11" (PDF). Professional Computing (PC) - Schneider International (in German). 3 (11): 100–103. Archived (PDF) from the original on 2019-04-24. Retrieved 2018-05-20.
^    a       b       c       d       e       f       g       h       i       j       k       l       m       n    Paul, Matthias R. (2002-03-26). "Updated CLS posted". freedos-dev mailing list. Archived from the original on 2018-10-04. Retrieved 2014-08-06.
^    a       b       c       d       e       f       g       h      Caldera DR-DOS 7.02 User Guide . Caldera, Inc. 1998 [1993, 1997]. Archived from the original on 2016-11-04. Retrieved 2013-08-10.
^    a       b       c       d    Paul, Matthias R. (2017-08-14) [2017-08-07]. "The continuing saga of Windows 3.1 in enhanced mode on OmniBook 300". MoHPC - the Museum of HP Calculators. Archived from the original on 2018-05-01. Retrieved 2018-05-01. […] set DRSYS=ON (optional to tell SYS you are aware of the fact that you're running it in a foreign environment and want to proceed anyway without having to individually ACK some warnings and extra info screens displayed in this scenario otherwise) […] 
^    a       b       c       d       e       f       g       h       i     CCI Multiuser DOS 7.22 GOLD Online Documentation. Concurrent Controls, Inc. (CCI). 1997-02-10. HELP.HLP.
  ^   CCI Multiuser DOS 7.22 GOLD Installation Guide. Concurrent Controls, Inc. (CCI). 1997-02-10. PRINTDOC.HLP.
^    a       b       c    Paul, Matthias R. (2002-02-20). "How to detect FreeCOM/FreeDOS in-batch?". freedos-dev mailing list. Archived from the original on 2018-11-06. Retrieved 2014-08-06.
  ^  Brink, Shawn (2018-11-17). "Environment Variables in Windows 10 - Complete List of Environment Variables in Windows 10". Windows Ten Forums. Archived from the original on 2019-03-27. Retrieved 2019-04-24.
^    a       b       c       d       e       f       g       h       i       j       k       l       m       n       o       p       q       r       s       t       u       v       w       x       y       z       aa       ab       ac       ad       ae       af       ag       ah       ai       aj       ak    Schulz, Hajo (2014-10-02). "Ordner für spezielle Fälle — Die "benannten Ordner" in Windows aus User- und Entwicklersicht" [Special purpose folders — Windows' "named folders" from a user's and developer's perspective].  c't - magazin für computertechnik  (in German). Heise Verlag. 2014 (22): 180–184. Archived from the original on 2016-07-09. Retrieved 2019-04-08.
^    a       b       c    Paul, Matthias R. (1997-05-01) [1993-10-01].  BATTIPs — Tips &amp; Tricks zur Programmierung von Batchjobs . MPDOSTIP (in German). 7: ERRORLEVEL abfragen. Archived from the original on 2017-08-23. Retrieved 2017-08-23. [5] [6] (NB. BATTIPS.TXT is part of MPDOSTIP.ZIP. The provided link points to a HTML-converted older version of the BATTIPS.TXT file.) [7]
^    a       b       c    Auer, Eric; Paul, Matthias R.; Hall, Jim (2015-12-24) [2003-12-31]. "MS-DOS errorlevels". Archived from the original on 2015-12-24.
  ^  Paul, Matthias R. (1998-01-09).  DELTREE.BAT R1.01 Extended file and directory delete . Caldera, Inc. Archived from the original on 2019-04-08. Retrieved 2019-04-08.
^    a       b      DR-DOS 7.03 WHATSNEW.TXT — Changes from DR-DOS 7.02 to DR-DOS 7.03 . Caldera, Inc. 1998-12-24. Archived from the original on 2019-04-08. Retrieved 2019-04-08.
  ^  Paul, Matthias R. (2001-06-10) [1995]. "DOS COUNTRY.SYS file format" (COUNTRY.LST file) (1.44 ed.). Archived from the original on 2016-04-20. Retrieved 2016-08-20.
  ^  Allen, William; Allen, Linda. "Windows 95/98/ME ERRORLEVELs". Archived from the original on 2011-07-07.
  ^   "Shell Variables". Bash Reference Manual.
 
Further reading[edit]
   Chen, Raymond (2010-05-06). "What are these strange =C: environment variables?". The New Old Thing. Microsoft. Archived from the original on 2018-05-27. Retrieved 2017-05-27.  
External links[edit]
   environ(7) : user environment – Linux Programmer's Manual – Overview, Conventions and Miscellanea
  environ(7)  – FreeBSD Miscellaneous Information Manual 
  environ(7)  – Darwin and macOS Miscellaneous Information Manual 
  environ(5)  – Solaris 10 Standards, Environments and Macros Reference Manual 
  "Environment Variables Wiki". Archived from the original on 2019-04-27. 
 User Environment Variables 
 fix setx.exe not found bug
Environment variable - Wikipedia
https://en.wikipedia.org/wiki/Environment_variable