⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch01_10.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 1] 1.10 Internal and External Commands </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:31:08Z"><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="ch01_01.htm"TITLE="1. Introduction"><LINKREL="prev"HREF="ch01_09.htm"TITLE="1.9 Which Shell Am I Running? "><LINKREL="next"HREF="ch01_11.htm"TITLE="1.11 How the Shell Executes Other Commands "></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="ch01_09.htm"TITLE="1.9 Which Shell Am I Running? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.9 Which Shell Am I Running? "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 1<BR>Introduction</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_11.htm"TITLE="1.11 How the Shell Executes Other Commands "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.11 How the Shell Executes Other Commands "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1040">1.10 Internal and External Commands </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1193"></A><ACLASS="indexterm"NAME="AUTOID-1195"></A>Some commands that you type are <EMCLASS="emphasis">internal</EM>, <EMCLASS="emphasis">built into</EM> the shell.For example, the <EMCLASS="emphasis">cd</EM> command is built-in.That is,the shell interprets that command and changes your<SPANCLASS="link">current directory (<ACLASS="linkend"HREF="ch01_21.htm"TITLE="Making Pathnames ">1.21</A>)</SPAN>for you.The <EMCLASS="emphasis">ls</EM> command, on the other hand, is an <EMCLASS="emphasis">external</EM>program stored in the file <EMCLASS="emphasis">/bin/ls</EM>.</P><PCLASS="para">The shell doesn't start a separate process to run internal commands.External commands require the shell to<SPANCLASS="link"><EMCLASS="emphasis">fork</EM> and <EMCLASS="emphasis">exec</EM> (<ACLASS="linkend"HREF="ch01_11.htm"TITLE="How the Shell Executes Other Commands ">1.11</A>)</SPAN>a new<SPANCLASS="link">subprocess (<ACLASS="linkend"HREF="ch38_03.htm"TITLE="Managing Processes: Overall Concepts ">38.3</A>)</SPAN>;this takes some time, especially on a busy system.(Article<ACLASS="xref"HREF="ch07_04.htm"TITLE="Faster Prompt Setting with Built-Ins ">7.4</A>shows an example where extra speed can be important.)</P><PCLASS="para">When you type the name of a command, the shell first checks to see ifit is a built-in command and, if so, executes it. If the command nameis an<SPANCLASS="link">absolute pathname (<ACLASS="linkend"HREF="ch01_21.htm"TITLE="Making Pathnames ">1.21</A>)</SPAN>beginning with <EMCLASS="emphasis">/</EM>, like <EMCLASS="emphasis">/bin/ls</EM>, there isno problem: the command is likewise executed. If the command isneither built-in, nor specified with an absolute pathname, the shelllooks in its<SPANCLASS="link">search path (<ACLASS="linkend"HREF="ch08_07.htm"TITLE="Setting Your Search Path ">8.7</A>)</SPAN>for an executable program or script with the given name.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1216"></A>The search path is exactly what its name implies: a list ofdirectories that the shell should look through for a command whosename matches what is typed.</P><PCLASS="para">The search path isn't built into the shell; it's something youspecify in 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><PCLASS="para"><SPANCLASS="link">By tradition (<ACLASS="linkend"HREF="ch21_04.htm"TITLE="Why Both /tmp and /usr/tmp? ">21.4</A>)</SPAN>,<ACLASS="indexterm"NAME="AUTOID-1223"></A><ACLASS="indexterm"NAME="AUTOID-1226"></A>UNIX system programs are kept in directories called<EMCLASS="emphasis">/bin</EM> and <EMCLASS="emphasis">/usr/bin</EM>, with additionalprograms usually used only by system administrators in <EMCLASS="emphasis">/etc</EM>and <EMCLASS="emphasis">/usr/etc</EM>.Many versions of UNIX also have programs storedin <EMCLASS="emphasis">/usr/ucb</EM> (named after the University of California atBerkeley, where many UNIX programs were written).There may be other directories containing programs. For example, theprograms that make up the<SPANCLASS="link">X Window System (<ACLASS="linkend"HREF="ch01_31.htm"TITLE="The X Window System ">1.31</A>)</SPAN>are stored in <EMCLASS="emphasis">/usr/bin/X11</EM>.Users or sites often also have their own directories where customcommands and scripts are kept, such as <EMCLASS="emphasis">/usr/local/bin</EM>.<ACLASS="indexterm"NAME="AUTOID-1238"></A><ACLASS="indexterm"NAME="AUTOID-1241"></A><ACLASS="indexterm"NAME="AUTOID-1244"></A></P><PCLASS="para">The search path is stored in an<SPANCLASS="link">environment variable (<ACLASS="linkend"HREF="ch06_01.htm#UPT-ART-1170"TITLE="What Environment Variables Are Good For ">6.1</A>)</SPAN>called<SPANCLASS="link"><EMCLASS="emphasis">PATH</EM> (<ACLASS="linkend"HREF="ch06_04.htm"TITLE="The PATH Environment Variable ">6.4</A>)</SPAN>.A typical <EMCLASS="emphasis">PATH</EM> setting might look something like this:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">PATH=/bin:/usr/bin:/usr/bin/X11:/usr/ucb:/home/tim/bin:</PRE></BLOCKQUOTE></P><PCLASS="para">The path is searched in order, so if there are two commands withthe same name, the one that is found first in the path will beexecuted.</P><PCLASS="para">You can<SPANCLASS="link">add new directories to your search path (<ACLASS="linkend"HREF="ch08_07.htm"TITLE="Setting Your Search Path ">8.7</A>)</SPAN>on the fly,but the path is usually set inshell setup files.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">TOR</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="ch01_09.htm"TITLE="1.9 Which Shell Am I Running? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.9 Which Shell Am I Running? "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="ch01_11.htm"TITLE="1.11 How the Shell Executes Other Commands "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.11 How the Shell Executes Other Commands "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">1.9 Which Shell Am I Running? </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">1.11 How the Shell Executes Other Commands </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 &amp; 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 + -