📄 ch08_02.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 8] 8.2 Introduction to bash</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-08-04T21:34: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="ch08_01.htm"TITLE="8. How the Shell Interprets What You Type"><LINKREL="prev"HREF="ch08_01.htm"TITLE="8.1 What the Shell Does "><LINKREL="next"HREF="ch08_03.htm"TITLE="8.3 Introduction to tcsh"></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="ch08_01.htm"TITLE="8.1 What the Shell Does "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 8.1 What the Shell Does "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 8<BR>How the Shell Interprets What You Type</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch08_03.htm"TITLE="8.3 Introduction to tcsh"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 8.3 Introduction to tcsh"BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-9901">8.2 Introduction to bash</A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-7428"></A>Until the early 1990s, most UNIX users worked interactively withthe C shell or the Bourne shell.The Korn Shell, an extended Bourne shell, had been around since themid '80s and was getting more popular.Since then, two freely available shells with even morefeatures-<SPANCLASS="link"><EMCLASS="emphasis">tcsh</EM> (<ACLASS="linkend"HREF="ch08_03.htm"TITLE="Introduction to tcsh">8.3</A>)</SPAN>and <EMCLASS="emphasis">bash</EM>-have been getting a lot of attention.This article introduces <EMCLASS="emphasis">bash</EM>.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-7435"></A>The "Bourne-again shell" (named with the usual punny FSF humor) comes fromthe Free Software Foundation.Although the name is a joke, the shell isn't!I've used UNIX shells for 15 years, and I was really impressedwhen I started to read about <EMCLASS="emphasis">bash</EM> (in O'Reilly & Associates'<EMCLASS="emphasis">Learning the bash Shell</EM>).Since then I've used <EMCLASS="emphasis">bash</EM> as my login shell.The shell has a lot of features that <EMCLASS="emphasis">ksh</EM> and <EMCLASS="emphasis">csh</EM>(and especially <EMCLASS="emphasis">sh</EM>!) don't, but I wouldn't call it "feepingcreaturism."[1]Here are some of my favorite features:</P><BLOCKQUOTECLASS="footnote"><PCLASS="para">[1] A term with a <CODECLASS="literal">:-)</CODE> you'll hear for "creeping featurism," whichmeans bloating software with lots of little-used features.</P></BLOCKQUOTE><OLCLASS="orderedlist"><LICLASS="listitem"><PCLASS="para">More than 60<SPANCLASS="link">shell variables (<ACLASS="linkend"HREF="ch06_08.htm"TITLE="Shell Variables ">6.8</A>)</SPAN>.These let me get information I need for<SPANCLASS="link">shell setup files (<ACLASS="linkend"HREF="ch02_02.htm"TITLE="Shell Setup Files-Which, Where, and Why ">2.2</A>)</SPAN>and also let me configure the shell to do what I want.</P></LI><LICLASS="listitem"><PCLASS="para">I like to<SPANCLASS="link">pack information into my shell prompt (<ACLASS="linkend"HREF="ch07_05.htm"TITLE="Multiline Shell Prompts ">7.5</A>)</SPAN>.(I haven't added the temperature in Rio de Janeiro yet, but I'm workingon it. <CODECLASS="literal">:-)</CODE>)<EMCLASS="emphasis">bash</EM> lets me run external UNIX commands, as well as shell commands,and update each prompt on-the-fly.It can also run UNIX or shell commands (and display the output if any)before each prompt is printed.For instance, <EMCLASS="emphasis">bash</EM> can run a quick system check and put notes inmy prompt (or the top of the window) to warn me about problems, countthe current users, tell me who's just logged in (and out), etc., etc.</P></LI><LICLASS="listitem"><PCLASS="para"><EMCLASS="emphasis">bash</EM> has both vi and Emacs<SPANCLASS="link">command-line editing (<ACLASS="linkend"HREF="ch11_13.htm"TITLE="Shell Command-Line Editing ">11.13</A>)</SPAN>.But it also has the original<SPANCLASS="link">C shell history substitution (<ACLASS="linkend"HREF="ch11_07.htm"TITLE="History Substitutions ">11.7</A>)</SPAN>.There are plenty of times when a short expression like <CODECLASS="literal">^k</CODE>(or even <CODECLASS="literal">!lpr:gs/2/3</CODE>)is faster than cursoring up and over to edit a previous command line.<EMCLASS="emphasis">bash</EM> lets me choose.</P></LI><LICLASS="listitem"><PCLASS="para">I stick to the Bourne Shell for any programs I distribute to otherusers:not enough people have <EMCLASS="emphasis">bash</EM> yet.But it does have some very nice features for scripts and shell functionsof my own - like powerful string-manipulation operators, file tests,and built-in integer arithmetic.</P></LI></OL><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="bash">bash</A><BR></TH><TDVALIGN="TOP"><EMCLASS="emphasis">bash</EM> is constantly being updated.The edition on the CD-ROM will probably be a little out ofdate by the time you get it.If you want a few more features, a few bug fixes (and, maybe, a fewnew bugs too), check a GNU archive on the Net for the latest version.</TD></TR></TABLE><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</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="ch08_01.htm"TITLE="8.1 What the Shell Does "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 8.1 What the Shell Does "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="ch08_03.htm"TITLE="8.3 Introduction to tcsh"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 8.3 Introduction to tcsh"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">8.1 What the Shell Does </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">8.3 Introduction to tcsh</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 + -