bash_quick_reference.pdf
(
437 KB
)
Pobierz
22743290 UNPDF
bash Quick
Reference
By Arnold Robbins
Contents
History ........................................................2
Overview of Features.................................2
Invoking the Shell ......................................3
Syntax..........................................................4
Functions ..................................................10
Variables ...................................................10
Arithmetic Expressions ...........................19
Command History ...................................20
Job Control...............................................25
Shell Options ............................................26
Command Execution ...............................28
Restricted Shells.......................................29
Built-in Commands..................................29
Resources ..................................................64
Copyright © 2006 O'Reilly Media, Inc.
ISBN: 0596527764
In this quick reference, you'll find
everything you need to know about the
bash shell. Whether you print it out or
read it on the screen, this book gives
you the answers to the annoying
questions that always come up when
you're writing shell scripts: What
characters do you need to quote? How
do you get variable substitution to do
exactly what you want? How do you
use arrays? It's also helpful for
interactive use.
If you're a Unix user or programmer,
or if you're using bash on Windows,
you'll find this quick reference
indispensable.
Find more at
pdfs.oreilly.com
CHAPTER 1
The Bash Shell
This reference covers Bash, which is the primary shell for GNU/Linux and Mac OS X. In
particular, it covers version 3.1 of Bash. Bash is available for Solaris and can be easily com-
piled for just about any other Unix system. This reference presents the following topics:
•
Histor y
•
Overvie w of features
•
Invoking the shell
•
Syntax
•
Functions
•
Variables
•
Arithmetic expressions
•
Command history
•
Job control
•
Shell options
•
Command execution
•
Restricted shells
•
Built-in commands
•
Resources
1
Histor y
The original Bourne shell distributed with V7 Unix in 1979 became the standard shell for
writing shell scripts. The Bourne shell is still be found in
/bin/sh
on many commercial
Unix systems. The Bourne shell itself has not changed that much since its initial release,
although it has seen modest enhancements over the years. The most notable new features
were the CDPATH variable and a built-in
test
command with System III (circa 1980),
command hashing and shell functions for System V Release 2 (circa 1984), and the addition
of job control features for System V Release 4 (1989).
Because the Berkeley C shell (
csh
) offered features that were more pleasant for interactive
use, such as command history and job control, for a long time the standard practice in the
Unix world was to use the Bourne shell for programming and the C shell for daily use. David
Korn at Bell Labs was the first developer to enhance the Bourne shell by adding
csh
-like fea-
tures to it: history, job control, and additional programmability. Eventually, the Korn shell’s
feature set surpassed both the Bourne shell and the C shell, while remaining compatible with
the Bourne shell for shell programming. Today, the POSIX standard defines the “standard
shell” language and behavior based on the System V Bourne shell, with a selected subset of
features from the Korn shell.
The Free Software Foundation, in keeping with its goal to produce a complete Unix work-
alike system, developed a clone of the Bourne shell, written from scratch, named “Bash,” the
Bourne-Again SHell. Over time, Bash has become a POSIX-compliant version of the shell,
with many additional features. A large part of these additional features overlap the features of
the Korn shell, but Bash is not an exact Korn shell clone.
Over view of Features
The Bash shell provides the following features:
•
Input/output redirection
•
Wildcard characters (metacharacters) for filename abbreviation
•
Shell variables and options for customizing your environment
•
A built-in command set for writing shell programs
•
Shell functions, for modularizing tasks within a shell program
•
Job control
•
Command-line editing (using the command syntax of either
vi
or Emacs)
•
Access to previous commands (command history)
•
Integer arithmetic
•
Arrays and arithmetic expressions
•
Command-name abbreviation (aliasing)
•
Upwards compliance with POSIX
2 Chapter 1 – The Bash Shell
•
Internationalization facilities
•
An arithmetic
for
loop
Invoking the Shell
The command interpreter for the Bash shell (
bash
) can be invoked as follows:
bash [
options
][
arguments
]
Bash can execute commands from a terminal, from a file (when the first
argument
is a script),
or from standard input (if no arguments remain or if
-s
is specified). The shell automatically
prints prompts if standard input is a terminal, or if
-i
is given on the command line.
On many systems,
/bin/sh
is a link to Bash. When invoked as
sh
, Bash acts more like the
traditional Bourne shell: login shells read
/etc/profile
and
˜/.profile
, and regular
shells read $ENV, if it’s set. Full details are available in the
bash
(1) manpage.
Options
-c
str
Read commands from string
str
.
-D
,
--dump-strings
Print all
$"..."
strings in the program.
-i
Create an interactive shell (prompt for input).
-O
option
Enable
shopt
option
option
.
-p
Start up as a privileged user. Don’t read $ENV or $BASH_ENV, don’t import functions
from the environment, and ignore the value of $SHELLOPTS. The normal fixed-
name startup files (such as
$HOME/.bash_profile
) are read.
-r
,
--restricted
Create a restricted shell.
-s
Read commands from standard input. Output from built-in commands goes to file
descriptor 1; all other shell output goes to file descriptor 2.
--debugger
Read the debugging profile at startup, turn on the
extdebug
option to
shopt
, and
enable function tracing. For use by the Bash debugger (see
http://bashdb.sourceforge.net
).
--dump-po-strings
Same as
-D
, but output in GNU
gettext
format.
--help
Print a usage message and exit successfully.
--init-file
file
,
--rcfile
file
Use
file
as the startup file instead of
˜/.bashrc
for interactive shells.
Invoking the Shell 3
Plik z chomika:
jacek_040
Inne pliki z tego folderu:
sharepoint_2013_users_guide_4th_edition.pdf
(51929 KB)
sharepoint_server_2010_administration_24_hour_trainer.pdf
(48210 KB)
solidworks_2007_bible.pdf
(42826 KB)
solidworks_2009_bible.pdf
(46173 KB)
sql_server_2012_data_integration_recipes.pdf
(50907 KB)
Inne foldery tego chomika:
- komputer
! HTML CSS XHTML
_ Informatyka. English
_ Informatyka. Kryptologia
_ Informatyka. Prolog
Zgłoś jeśli
naruszono regulamin