📄 bashref.html
字号:
<HTML><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><!-- Created on July, 15 2002 by texi2html 1.64 --><!-- Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author) Karl Berry <karl@freefriends.org> Olaf Bachmann <obachman@mathematik.uni-kl.de> and many others.Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>Send bugs and suggestions to <texi2html@mathematik.uni-kl.de> --><HEAD><TITLE>Bash Reference Manual: </TITLE><META NAME="description" CONTENT="Bash Reference Manual: "><META NAME="keywords" CONTENT="Bash Reference Manual: "><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META NAME="Generator" CONTENT="texi2html 1.64"></HEAD><BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000"><A NAME="SEC_Top"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H1>Bash Reference Manual</H1></P><P>This text is a brief description of the features that are present inthe Bash shell.</P><P>This is Edition 2.5b, last updated 15 July 2002,of <CITE>The GNU Bash Reference Manual</CITE>,for <CODE>Bash</CODE>, Version 2.05b.</P><P>Copyright (C) 1991-2002 Free Software Foundation, Inc.</P><P>Bash contains features that appear in other popular shells, and somefeatures that only appear in Bash. Some of the shells that Bash hasborrowed concepts from are the Bourne Shell (<TT>`sh'</TT>), the Korn Shell(<TT>`ksh'</TT>), and the C-shell (<TT>`csh'</TT> and its successor,<TT>`tcsh'</TT>). The following menu breaks the features up intocategories based upon which one of these other shells inspired thefeature.</P><P>This manual is meant as a brief introduction to features found inBash. The Bash manual page should be used as the definitivereference on shell behavior.</P><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC1">1. Introduction</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">An introduction to the shell.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC4">2. Definitions</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Some definitions used in the rest of this manual.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC5">3. Basic Shell Features</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">The shell "building blocks".</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC55">4. Shell Builtin Commands</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Commands that are a part of the shell.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC60">5. Shell Variables</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Variables used or set by Bash.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC63">6. Bash Features</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Features found only in Bash.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC86">7. Job Control</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">A chapter describing what job control is and how Bash allows you to use it.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC114">9. Using History Interactively</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Chapter dealing with history expansion rules.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC90">8. Command Line Editing</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Chapter describing the command line editing features.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC121">10. Installing Bash</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">How to build and install Bash on your system.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC130">A. Reporting Bugs</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">How to report bugs in Bash.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC131">B. Major Differences From The Bourne Shell</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">A terse list of the differences between Bash and historical versions of /bin/sh.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC133">Index of Shell Builtin Commands</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Index of Bash builtin commands.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC134">Index of Shell Reserved Words</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Index of Bash reserved words.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC135">Parameter and Variable Index</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Quick reference helps you find the variable you want.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC136">Function Index</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Index of bindable Readline functions.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC137">Concept Index</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">General index for concepts described in this manual.</TD></TR></TABLE></BLOCKQUOTE><P><HR SIZE=1><A NAME="SEC1"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC2"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[ << ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC4"> >> </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><A NAME="Introduction"></A><H1> 1. Introduction </H1><!--docid::SEC1::--><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC2">1.1 What is Bash?</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">A short description of Bash.</TD></TR></TABLE><br><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC3">1.2 What is a shell?</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">A brief introduction to shells.</TD></TR></TABLE></BLOCKQUOTE><P><A NAME="What is Bash?"></A><HR SIZE="6"><A NAME="SEC2"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC1"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC3"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[ << ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC1"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC4"> >> </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 1.1 What is Bash? </H2><!--docid::SEC2::--><P>Bash is the shell, or command language interpreter,for the GNU operating system.The name is an acronym for the <SAMP>`Bourne-Again SHell'</SAMP>,a pun on Stephen Bourne, the author of the direct ancestor ofthe current Unix shell <CODE>/bin/sh</CODE>, which appeared in the Seventh Edition Bell Labs Research versionof Unix.</P><P>Bash is largely compatible with <CODE>sh</CODE> and incorporates usefulfeatures from the Korn shell <CODE>ksh</CODE> and the C shell <CODE>csh</CODE>.It is intended to be a conformant implementation of the IEEEPOSIX Shell and Tools specification (IEEE Working Group 1003.2).It offers functional improvements over <CODE>sh</CODE> for both interactive andprogramming use.</P><P>While the GNU operating system provides other shells, includinga version of <CODE>csh</CODE>, Bash is the default shell.Like other GNU software, Bash is quite portable. It currently runson nearly every version of Unix and a few other operating systems -independently-supported ports exist for MS-DOS, OS/2,Windows 95/98, and Windows NT.</P><P><A NAME="What is a shell?"></A><HR SIZE="6"><A NAME="SEC3"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC2"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC4"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[ << ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC1"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC4"> >> </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 1.2 What is a shell? </H2><!--docid::SEC3::--><P>At its base, a shell is simply a macro processor that executescommands. A Unix shell is both a command interpreter, whichprovides the user interface to the rich set of GNU utilities,and a programming language, allowing these utilitites to becombined. Files containing commands can be created, and becomecommands themselves. These new commands have the same status assystem commands in directories such as <TT>`/bin'</TT>, allowing usersor groups to establish custom environments. </P><P>A shell allows execution of GNU commands, both synchronously andasynchronously.The shell waits for synchronous commands to complete before acceptingmore input; asynchronous commands continue to execute in parallelwith the shell while it reads and executes additional commands.The <EM>redirection</EM> constructs permitfine-grained control of the input and output of those commands.Moreover, the shell allows control over the contents of commands'environments.Shells may be used interactively or non-interactively: they acceptinput typed from the keyboard or from a file.</P><P>Shells also provide a small set of built-incommands (<EM>builtins</EM>) implementing functionality impossibleor inconvenient to obtain via separate utilities.For example, <CODE>cd</CODE>, <CODE>break</CODE>, <CODE>continue</CODE>, and<CODE>exec</CODE>) cannot be implemented outside of the shell becausethey directly manipulate the shell itself.The <CODE>history</CODE>, <CODE>getopts</CODE>, <CODE>kill</CODE>, or <CODE>pwd</CODE>builtins, among others, could be implemented in separate utilities,but they are more convenient to use as builtin commands.All of the shell builtins are described insubsequent sections.</P><P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -