|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T b
Length: 14457 (0x3879) Types: TextFile Names: »bash.texinfo«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89 └─⟦ca1f037a2⟧ »./bash-1.04.tar.Z« └─⟦46465a4db⟧ └─⟦this⟧ »bash-1.04/documentation/bash.texinfo«
\input texinfo.tex @c -*- texinfo -*- @setfilename bash.info @ifinfo This file documents the GNU Bourne Again SHell. Copyright (C) 1988 Free Software Foundation, Inc. Authored by Brian Fox. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. @ignore Permission is granted to process this file through Tex and print the results, provided the printed document carries copying permission notice identical to this one except for the removal of this paragraph (this paragraph not being relevant to the printed manual). @end ignore Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the GNU Copyright statement is available to the distributee, and provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions. @end ifinfo @node Top, , , (DIR) This document describes the GNU shell utility called @dfn{Bash}. This document should be considered a technical reference manual; it is primarily provided to explain how Bash works, not to explain why a shell is useful. Novice users should refer to the @cite{Bash User's Guide}, which isn't written yet. @menu * Introduction:: Description of Bash, and how it is similar to other shells. * Running Commands:: How to ask the shell to run a particular program. * Word Expansion:: How the shell processes your input before it arrives at other programs. * Command Line Editing:: Editing lines that you type, and how to get at previously typed lines. * History Substitution:: `!' style history substitution. * Aliases:: Textual substitution of command words. * Functions:: How to generalize a group of related commands * Scripts:: Writing shell programs with Bash. * Builtins:: Description of commands that are built into the shell. * Variable Index:: Index of shell variables. * Concept Index:: Index of shell concepts. * Command Index:: Index of builtin shell commands. * Glossary:: Collection of `Unix Weenie' terms. @end menu @node Introduction, Running Commands, Top, Top @unnumbered Introduction You are reading the Bash Technical Reference Manual. This manual is here to tell you what features are available in Bash, as well as to describe the operation of the interpreted programming language that is part of Bash. @example foo @result{} bar which is like saying that bar @equiv{} baz @end example Bash is a Posix compatible shell, which leans towards the semantics of the Bourne shell, as opposed to the C-shell (@dfn{csh}). However, some of the features found in csh (such as job control) are also present in Bash, which makes it pleasant for interactive use. Additionally, features found in the Korn shell (@cite{ksh}), are also present in Bash. Hopefully, this makes Bash a superset of the desireable features found in other shells. @menu * Differences:: A quick overview of the features available in Bash. * Installation:: How to install Bash on your system. @end menu @node Differences, Installation, Introduction, Introduction @section Differences and Features See the file FEATURES in the main Bash ditribution. @node Installation, , Differences, Introduction @section Installation Installing Bash is easy, just run @code{make} in the main distribution directory. Simply edit the Makefile parameters DESTDIR, TARGET, and OS, to match the kind of system that you are using. If you do not have one of the advertised systems, it is quite possible that it falls under Bsd or SYSV. @node Running Commands, Word Expansion, Introduction, Top @chapter Running Commands @menu * Simple Commands:: Execution of simple commands. * Pipes:: Connecting commands together is useful for filtering output. * Redirections:: What to do with the final output, and where to get input from. * Job Control:: Running commands in the background. Stopping and resuming commands. @end menu @node Simple Commands, , Running Commands, Running Commands @section Simple Commands By far, the most common use of a shell is to execute simple but useful commands, one by one, such as @dfn{ls}, @dfn{cc}, or @dfn{cp}. Such commands are stored in files (with a few exceptions), and @dfn{running} them means to cause the file to be loaded, and the code in that file to be executed. There is a function in the operating system which can execute a file, passing it some arguments. However, that is all that the function can do. If we had to speak directly to that function, without an intervening shell, it might look like this: @example /bin/ls -l ./foo.c ./bar.c ./fred.c @end example instead of like this: @example ls -l *.c @end example The shell helps us by performing @dfn{wildcard expansion} (*.c), and @dfn{command lookup} (ls --> /bin/ls). The shell can help us in other ways such as @dfn{Word Expansion} (@pxref{Word Expansion}). @node Pipes, Redirections, Simple Commands, Running Commands @section Pipes A @dfn{pipe} is a channel of communication between two processes. The simplest and most direct form of pipe connects the output of one process to the input of another. In this way, the second process acts as a @dfn{filter} for the first process. With Bash, you can pipe the output of one command into the input of another by placing a vertical bar (@key{|}) between them. For example, say we want to view a detailed listing of a directory with a large number of files. If we simply issue the @code{ls -l} command, the listing will scroll by at an alarming rate, and we will not be able to read the output before the majority of it scrolls off of the screen. We can attach the output of the @code{ls -l} command to the input of a @code{more} command with the pipe character thusly: @example @code{ls -l | more} @end example Now, all of the output from @code{ls -l} will be the input for @code{more}, whose job it is to show its input a screen at a time. @node Redirections, Job Control, Pipes, Running Commands @section Redirections We have already seen how to make the output of one command be the input of another. But that isn't flexible enough. We would like to be able to direct output into a file, or to read input from a file. Bash's @dfn{redirection} operators let us do just that. @menu * Redirection Operators:: What kinds of redirection are available? * Redirecting File Descriptors:: Attaching arbitrary file descriptors to input and output. @end menu @node Redirection Operators, Redirecting File Descriptors, , Redirections @subsection Redirection Operators Redirection operators can be placed anywhere on a command line. They are acted upon in the order seen, from left to right. Here are the redirection operators. @table @code @item cat foo bar >baz Create or truncate the file named @file{baz}, and then place the output from @code{cat}ing the files @file{foo} and @file{bar} into it. Note that the @code{>} only redirects the standard output; error messages printed by @code{cat} will appear on the terminal, not in the file @file{baz}. @item cat foo >>baz Append the contents of the file @file{foo} to the contents of the file @file{baz}. If @file{baz} does not exist, create it first. @item cat <baz Make @file{baz} be the standard input for the @code{cat} command. @item cat foo &>baz Create or truncate the file @file{baz}, and place the output of @code{cat}ing the file @file{foo} into it. This operator redirects both standard output and standard error so if the @code{cat} command produces any errors, that output will also be placed into @file{foo}. @item cat <<@var{word} Read input from the current source until a line containing only @var{word} is seen. All of the lines read upto that line are then the input for the @code{cat} command. @example @code{bash$} cat <<foo @code{bash>} This input will become the input to the cat command. @code{bash>} The input is ended when `foo' is seen on a line by itself. @code{bash>} Note that `foo' can be seen in other places, as long as @code{bash>} it is not seen by itself. @code{bash>} foo @end example @item cat <<-@var{word} This is identical to @code{cat <<@var{word}} except that leading TAB characters are stripped from each line of input as it is read. @end table @node Redirecting File Descriptors, , Redirection Operators, Redirections @subsection Redirecting File Descriptors In addition to attaching @code{stdin}, @code{stdout}, and @code{stderr} to various files, you can also duplicate the contents of an existing file descriptor into another file descriptor. This means that if you know that you have a file open on a descriptor (e.g 1, usually stdout), you can direct output written to another descriptor (e.g. 2, usually stderr), to the same destination. The redirection @node Word Expansion, Command Line Editing, Running Commands, Top @chapter Word Expansion Each input line to the shell consists of one or more @dfn{words}. Some of the text may look like several English words, but may be grouped into one shell word with the use of quoting characters. Some of the text may contain dollar signs `$'; the dollar sign is special to the shell, and signifies the beginning of a variable name. @dfn{Word expansion} consists of massaging the input that you have typed in order to generate a simple command complete with arguments. Here are the major types of word expansion. @menu * Command Substitution:: The output text of a command can be the direct input to a shell command. * Variable Substitution:: Words containing an unquoted `$' contain @dfn{variables} which are replaced by their values. * Filename Substitution:: Filename substitution (or @dfn{globbing}, as it is commonly known) makes it possible to specify many similar files in one simple expression. @end menu @node Command Substitution, Variable Substitution, , Word Expansion @section Command Substitution Text inside of backquotes (`) is expanded by running the command contained within. For example, @example @code{echo `whoami`} @end example displays your username, since that is what the output from the @code{whoami} command produced. If I am using the shell on the machine Vision at UCSB, and I type @example @code{echo `whoami`@`hostname`} @end example the output looks like @display @code{bfox@@vision.ucsb.edu} @end display @node Variable Substitution, Filename Substitution, Command Substitution, Word Expansion @section Variable Substitution @node Filename Substitution, ,Variable Substitution, Word Expansion @section Filename Substitution @node Command Line Editing, History Substitution, Word Expansion, Top @chapter Command Line Editing The features available for interactive command line editing are taken from the GNU Readline Library. This library is used by many GNU programs, including GDB. @menu * Readline Top:: How to use the basic features of the Readline Library. * Bash Readline:: Additional features and baggage specific to Bash. @end menu @include ../readline/inc-readline.texinfo @node Bash Readline, ,Readline Top, Command Line Editing @section Bash Readline What features Bash specifically adds to readline. @node History Substitution, Job Control, Command Line Editing, Top @chapter History Substitution @include ../readline/inc-history.texinfo @node Job Control, Aliases, History Substitution, Top @chapter Job Control @node Aliases, Functions, Job Control, Top @chapter Aliases @node Functions, Scripts, Aliases, Top @chapter Functions @menu Local Variables:: Creating local variables; using them within functions. @end menu @node Local Variables, , , Functions @subsection Local Variables Bash supports the use of local variables within an executing function. A local variable shadows the value of a previously defined variable (local or not) with the same name. The local variable is visible to the current function level and to any functions or programs invoked from that function, and to their children as well. Local variables differ from other variables in only one way: when the function that defined the variable exits, the local variable goes away, and any previously defined variable with the same name becomes visible again. There is no way to have changes made to a local variable affect the value of any previous variable with the same name. Local variables are created with the @code{declare} or @code{local} commands. Here is the declaration of a function which uses a local version of the PATH variable, and executes all of its arguments using a PATH which contains only /bin. @example using_bin () @{ local PATH=/bin eval $* @} @end example A useful call to this function might look like: @example using_bin "rm *.texinfo; cp ../*.texinfo ." @end example @node Scripts, Builtins, Functions, Top @chapter Scripts @node Variable Index, Scripts, Concept Index, Top @unnumbered Variable Index @node Concept Index, Command Index, Variable Index, Top @unnumbered Concept Index @node Command Index, Glossary, Concept Index, Top @unnumbered Command Index @node Glossary, , Command Index, Top @unnumbered Glossary The following are terms and phrases commonly used by `Unix Weenies'. I have placed these here in the hopes that people may find some relief from the deluge of distorted English that hackers seem to be fond of. Although some of these words are common to many types of computer nerds, others of them are solely used by Unix style nerds. These are marked accordingly. Pronounciations are very important; where not obvious, these are marked as well. Happy Hacking! @table @code @item bang The name for the `!' character, as in "type bang dollar for the last arg." @item star The name for the `*' character, as in "don't type are em star, you'll be sorry." @item dot The name for the `.' character, as in "delete all of the dot oh files." This can be used in conjunction with the above names, and in fact usually is. For example, if you wanted to tell someone to type the text @w{"rm -f !$/*.o"}, you would say "just type are em dash ef bang dollar slash star dot oh". @end table @contents @bye \f Local Variables: compile-command: "makeinfo -fc 72 bash.texinfo" fill-column: 72 End: