Why are there both TMP and TEMP environment variables? (2015)
Source: Hacker News
History
CP/M (1973)
The original micro‑computer operating system, CP/M, had no environment variables. Consequently, there was neither a TMP nor a TEMP variable. Programs that needed a temporary‑file location had to rely on program‑specific configuration, such as patching a byte in the executable to indicate the drive letter.
MS‑DOS (1981)
When the 8086 processor and MS‑DOS arrived, the design was heavily inspired by CP/M. One of the first additions MS‑DOS made beyond CP/M compatibility was environment variables. Early MS‑DOS programs, being ports of CP/M software, ignored these variables.
As native MS‑DOS applications emerged, developers began using environment variables for configuration. Two variables—TEMP and TMP—became the de‑facto standards for indicating a temporary‑file directory.
MS‑DOS 2.0 introduced piping, which MS‑DOS simulated by writing the first program’s output to a temporary file and then feeding that file to the second program. For this purpose the OS used the TEMP variable to determine where to create those temporary files.
Different programs chose different preferences:
DISKCOPYandEDITlooked forTEMPfirst, thenTMP.- The Windows API function
GetTempFileNamechecksTMPbeforeTEMP.
Windows
Windows inherited the dual‑variable situation. The original authors of GetTempFileName preferred TMP, so most Windows programs that rely on this API will use the directory specified by TMP unless they explicitly check TEMP.
When you open the Environment Variables dialog in Windows, you will still see both TMP and TEMP listed, each potentially pointing to different locations. The variable actually used depends on the program’s implementation.
Practical Takeaway
- The directory used for temporary files is program‑dependent.
- If you want consistent behavior across most Windows applications, ensure that both
TMPandTEMPpoint to the same folder. - For legacy MS‑DOS utilities,
TEMPmay be the preferred variable.