📄 ch06_03.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 6] 6.3 Predefined Environment Variables </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-10-23T15:37:56Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch06_01.htm"TITLE="6. Shell and Environment Variables"><LINKREL="prev"HREF="ch06_02.htm"TITLE="6.2 Parent-Child Relationships "><LINKREL="next"HREF="ch06_04.htm"TITLE="6.4 The PATH Environment Variable "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch06_02.htm"TITLE="6.2 Parent-Child Relationships "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 6.2 Parent-Child Relationships "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 6<BR>Shell and Environment Variables</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch06_04.htm"TITLE="6.4 The PATH Environment Variable "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 6.4 The PATH Environment Variable "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1171">6.3 Predefined Environment Variables </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5818"></A>We've said that environment variables are used to store informationthat you'd rather not worry about, and that there are a number ofstandard environment variables that many UNIX programs use.These are often called "predefined" environmentvariables - not because their values are predefined, but becausetheir names and uses are predefined. Here are the most importantones:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><SPANCLASS="link"><EMCLASS="emphasis">PATH</EM> (<ACLASS="linkend"HREF="ch06_04.htm"TITLE="The PATH Environment Variable ">6.4</A>)</SPAN><ACLASS="indexterm"NAME="AUTOID-5825"></A>contains your<SPANCLASS="link">command search path (<ACLASS="linkend"HREF="ch08_07.htm"TITLE="Setting Your Search Path ">8.7</A>)</SPAN>.This is a list of directories inwhich the shell looks to find commands.It's usually set in one of your<SPANCLASS="link">shell setup files (<ACLASS="linkend"HREF="ch02_02.htm"TITLE="Shell Setup Files-Which, Where, and Why ">2.2</A>)</SPAN>.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5831"></A><ACLASS="indexterm"NAME="AUTOID-5834"></A><ACLASS="indexterm"NAME="AUTOID-5836"></A><EMCLASS="emphasis">EDITOR</EM> can be loaded with the name of your favorite editor.It's usually set in one of your shell setup files.Some programsdistinguish between <EMCLASS="emphasis">EDITOR</EM> (usually set to a<SPANCLASS="link">line editor (<ACLASS="linkend"HREF="ch33_01.htm#UPT-ART-7965"TITLE="Why Line Editors Aren't Dinosaurs ">33.1</A>)</SPAN>such as <EMCLASS="emphasis">ed</EM>)<ACLASS="indexterm"NAME="AUTOID-5843"></A>and <EMCLASS="emphasis">VISUAL</EM> (set to a full-screen editor like <EMCLASS="emphasis">vi</EM>).Many peopledon't follow that convention; they set both to the same editor.(The Korn shell checks <EMCLASS="emphasis">VISUAL</EM> and <EMCLASS="emphasis">EDITOR</EM>, in that order,to determine your<SPANCLASS="link">command editing mode (<ACLASS="linkend"HREF="ch11_13.htm"TITLE="Shell Command-Line Editing ">11.13</A>)</SPAN>.)</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5852"></A><SPANCLASS="link"><EMCLASS="emphasis">PRINTER</EM> (<ACLASS="linkend"HREF="ch43_04.htm"TITLE="Using Different Printers ">43.4</A>)</SPAN>can be loaded with the name of your default printer.It's quite useful ata site with many printers - you don't need to tell <SPANCLASS="link"><EMCLASS="emphasis">lpr</EM> (<ACLASS="linkend"HREF="ch43_02.htm"TITLE="Introduction to Printing on UNIX ">43.2</A>)</SPAN>which printer to use.This variable is usually set in one ofyour shell setup files.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5860"></A><ACLASS="indexterm"NAME="AUTOID-5862"></A><EMCLASS="emphasis">PWD</EM> contains the absolute pathname of your current directory.It's set automatically by the <EMCLASS="emphasis">cd</EM> command in some UNIX shells.<EMCLASS="emphasis">PWD</EM> may be<SPANCLASS="link">fooled (<ACLASS="linkend"HREF="ch14_13.htm"TITLE="Which Directory Am I in, Really? ">14.13</A>)</SPAN>by <EMCLASS="emphasis">cd</EM>ing through symbolic links.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5871"></A><ACLASS="indexterm"NAME="AUTOID-5873"></A><ACLASS="indexterm"NAME="AUTOID-5875"></A><SPANCLASS="link"><EMCLASS="emphasis">HOME</EM> (<ACLASS="linkend"HREF="ch14_11.htm"TITLE="Finding (Anyone's) Home Directory, Quickly ">14.11</A>)</SPAN>(called <EMCLASS="emphasis">LOGDIR</EM> on some systems) contains the absolutepathname of your home directory.It's set automatically when youlog in.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5882"></A><EMCLASS="emphasis">SHELL</EM> contains the absolute pathname of your login shell.It's set automatically whenever you log in.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5887"></A><ACLASS="indexterm"NAME="AUTOID-5889"></A><EMCLASS="emphasis">USER</EM> or <EMCLASS="emphasis">LOGNAME</EM> contains your username.It's set automatically when you log in, and doesn't change.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5895"></A><SPANCLASS="link"><EMCLASS="emphasis">TERM</EM> (<ACLASS="linkend"HREF="ch05_10.htm"TITLE="Finding What Terminal Names You Can Use ">5.10</A>)</SPAN>contains the name of your terminal type in the <EMCLASS="emphasis">termcap</EM> or<EMCLASS="emphasis">terminfo</EM> database.It's usually set in a shell setupfile.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5903"></A><ACLASS="indexterm"NAME="AUTOID-5905"></A><SPANCLASS="link"><EMCLASS="emphasis">TERMCAP</EM> (<ACLASS="linkend"HREF="ch05_04.htm"TITLE="Setting the TERMCAP Variable with tset ">5.4</A>)</SPAN>can be loaded with the complete <EMCLASS="emphasis">termcap</EM> database entry for theterminal you are using. This may make some programs start up morequickly, but it's not necessary.It's set (under some conditions)by the <EMCLASS="emphasis">tset</EM>command, which is usually run in your shell setup file.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5913"></A><ACLASS="indexterm"NAME="AUTOID-5915"></A><EMCLASS="emphasis">ENV</EM> contains the name of an initialization file to be executed whenevera new Korn shell is started.(See article <ACLASS="xref"HREF="ch02_02.htm"TITLE="Shell Setup Files-Which, Where, and Why ">2.2</A>.)Korn shell only.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5922"></A><EMCLASS="emphasis">PAGER</EM> can be set to the name ofyour favorite page-by-page screen display program like<SPANCLASS="link"><EMCLASS="emphasis">more</EM> (<ACLASS="linkend"HREF="ch25_03.htm"TITLE="Using more to Page Through Files ">25.3</A>)</SPAN>or<SPANCLASS="link"><EMCLASS="emphasis">less</EM> (<ACLASS="linkend"HREF="ch25_04.htm"TITLE='The "less" Pager: More than "more"'>25.4</A>)</SPAN>.(Programs like<SPANCLASS="link"><EMCLASS="emphasis">man</EM> (<ACLASS="linkend"HREF="ch50_01.htm#UPT-ART-4910"TITLE="UNIX Online Documentation ">50.1</A>)</SPAN>use <EMCLASS="emphasis">PAGER</EM> to determine which paging program to use if their output islonger than a single screen.)</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5934"></A><ACLASS="indexterm"NAME="AUTOID-5936"></A><SPANCLASS="link"><EMCLASS="emphasis">EXINIT</EM> (<ACLASS="linkend"HREF="ch30_35.htm"TITLE="Out of Temporary Space? Use Another Directory ">30.35</A>, <ACLASS="linkend"HREF="ch06_10.htm"TITLE="Running a Command with a Temporarily Different Environment ">6.10</A>)</SPAN>stores setup options for the <EMCLASS="emphasis">vi</EM> editor (and the <EMCLASS="emphasis">ex</EM>editor, where <EMCLASS="emphasis">EXINIT</EM> got its name).</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5946"></A><ACLASS="indexterm"NAME="AUTOID-5948"></A><EMCLASS="emphasis">PS1</EM> contains the primary prompt (i.e., interactive command prompt) forBourne shells. (The C shell doesn't store the prompt inan environment variable.It uses a shell variable called<EMCLASS="emphasis">prompt</EM> because the<SPANCLASS="link"><EMCLASS="emphasis">.cshrc</EM> file (<ACLASS="linkend"HREF="ch02_02.htm"TITLE="Shell Setup Files-Which, Where, and Why ">2.2</A>)</SPAN>is read to set up each instance of the shell.See article<ACLASS="xref"HREF="ch07_02.htm"TITLE="Basics of Setting the Prompt ">7.2</A>.)</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5958"></A><SPANCLASS="link"><EMCLASS="emphasis">PS2</EM> (<ACLASS="linkend"HREF="ch09_13.htm"TITLE="Multiline Commands, Secondary Prompts ">9.13</A>)</SPAN>contains the secondary prompt (used within compound commands like<EMCLASS="emphasis">while</EM> and <EMCLASS="emphasis">for</EM>) for Bourne shells.</P></LI><LICLASS="listitem"><PCLASS="para"><SPANCLASS="link"><EMCLASS="emphasis">MANPATH</EM> (<ACLASS="linkend"HREF="ch50_10.htm"TITLE="Make Your Own Man Pages Without Learning troff">50.10</A>)</SPAN>,<ACLASS="indexterm"NAME="AUTOID-5968"></A><ACLASS="indexterm"NAME="AUTOID-5971"></A><ACLASS="indexterm"NAME="AUTOID-5974"></A><ACLASS="indexterm"NAME="AUTOID-5978"></A>if your<SPANCLASS="link"><EMCLASS="emphasis">man</EM> (<ACLASS="linkend"HREF="ch50_01.htm#UPT-ART-4910"TITLE="UNIX Online Documentation ">50.1</A>)</SPAN>command supports it, is a colon-separated list of directories to searchfor manual pages.</P></LI><LICLASS="listitem"><PCLASS="para"><SPANCLASS="link"><EMCLASS="emphasis">TZ</EM> (<ACLASS="linkend"HREF="ch06_06.htm"TITLE="The TZ Environment Variable ">6.6</A>)</SPAN><ACLASS="indexterm"NAME="AUTOID-5986"></A><ACLASS="indexterm"NAME="AUTOID-5988"></A>contains the time zone. This is a name of a file in<EMCLASS="emphasis">/usr/lib/zoneinfo</EM> that provides time zone information for yourlocality. It is read by commands like<SPANCLASS="link"><EMCLASS="emphasis">date</EM> (<ACLASS="linkend"HREF="ch51_10.htm"TITLE="The date Command ">51.10</A>, <ACLASS="linkend"HREF="ch06_07.htm"TITLE="What Time Is It in Japan? ">6.7</A>)</SPAN>.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5995"></A><EMCLASS="emphasis">DISPLAY</EM> is used by the <SPANCLASS="link">X Window System (<ACLASS="linkend"HREF="ch01_31.htm"TITLE="The X Window System ">1.31</A>)</SPAN>to identify the displayserver (keyboard and screen handling program)that will be used for input and output by X applications.</P></LI></UL><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-6000"></A><ACLASS="indexterm"NAME="AUTOID-6003"></A>Because Bourne-type shells don't make as strict a distinctionbetween environment variables and shell variables as the C shell does,we've includeda few things here that might not be on other people's lists.</P><PCLASS="para">We may have implied that environment variables are relatively constant(like your favorite editor). That's not true.For example, in a windowing environment, the current length ofyour window might be kept in an environment variable. That can changeas often as you resize your window.What is true (fortunately)is exactly what we've said: environment variables store information that you'd rather not have to worry about.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch06_02.htm"TITLE="6.2 Parent-Child Relationships "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 6.2 Parent-Child Relationships "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch06_04.htm"TITLE="6.4 The PATH Environment Variable "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 6.4 The PATH Environment Variable "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">6.2 Parent-Child Relationships </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">6.4 The PATH Environment Variable </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -