Bash Reference Manual/zh:修订间差异

来自Ubuntu中文
跳到导航跳到搜索
Jinzd留言 | 贡献
Jinzd留言 | 贡献
 
(未显示同一用户的6个中间版本)
第1行: 第1行:
本文引自[https://www.gnu.org/software/bash/manual/bash.html#Readline-Bare-Essentials https://www.gnu.org/software/bash/manual/bash.html#Readline-Bare-Essentials].
本文引自[https://www.gnu.org/software/bash/manual/bash.html#Readline-Bare-Essentials https://www.gnu.org/software/bash/manual/bash.html].


<span style="font-size:1.2em">'''Bash特性'''</span>
<span style="font-size:1.2em">'''Bash特性'''</span>
第141行: 第141行:


=Definitions=
=Definitions=
These definitions are used throughout the remainder of this manual.
这些定义将在本手册的其余部分使用到。
POSIX(可移植操作系统接口)
: A family of open system standards based on Unix. Bash is primarily concerned with the Shell and Utilities portion of the POSIX 1003.1 standard.
: 基于Unix家族的一个开放系统标准。Bash主要关心POSIX 1003.1标准的Shell以及工具部分。
blank
: A space or tab character.
: 一个空格(space)或制表符(tab)。
builtin(内建/嵌入)
: A command that is implemented internally by the shell itself, rather than by an executable program somewhere in the file system.
: 一个由shell自己内部实现的的命令,它不是一个存储于文件系统中的可执行程序。
control operator(控制操作符)
: A token that performs a control function. It is a newline or one of the following: ‘||’, ‘&&’, ‘&’, ‘;’, ‘;;’, ‘|’, ‘|&’, ‘(’, or ‘)’.
: 一个记号并执行一个控制功能。它是一个换行符或以下东东:‘||’, ‘&&’, ‘&’, ‘;’, ‘;;’, ‘|’, ‘|&’, ‘(’, or ‘)’。
exit status(退出状态)
: The value returned by a command to its caller. The value is restricted to eight bits, so the maximum value is 255.
: 由命令返回该值到它的调用者。此值限于一个8比特值,所以它的最大值是255。
field(字段)
: A unit of text that is the result of one of the shell expansions. After expansion, when executing a command, the resulting fields are used as the command name and arguments.
: 一个文本单位是该shell扩展的结果。扩展之后,当执行一个命令时,这个结果字段被用作命令名或参数。
filename
: A string of characters used to identify a file.
: 由字符组成的字符串用于识别一个文件。
job(作业)
: A set of processes comprising a pipeline, and any processes descended from it, that are all in the same process group.
: 由一组操作组成的操作流水,它的任何后裔操作均属于同一个操作组。
job control(作业控制)
: A mechanism by which users can selectively stop (suspend) and restart (resume) execution of processes.
: 一套机制,用户可以选择性地停止和重启操作的执行。
metacharacter(元字符)
: A character that, when unquoted, separates words. A metacharacter is a blank or one of the following characters: ‘|’, ‘&’, ‘;’, ‘(’, ‘)’, ‘<’, or ‘>’.
: 当一个字符,当它未被引号引用,或者是单独出现。一个元字符可以是一个空格或以下单个出现的字符:‘|’,‘&’,‘;’,‘(’, ‘)’,‘<’ 或者 ‘>’。
name(名称)
: A word consisting solely of letters, numbers, and underscores, and beginning with a letter or underscore. Names are used as shell variable and function names. Also referred to as an identifier.
: 一个仅由字母、数字及下划线组成的词,名字被用于shell的变量及函数名称。也被认为是一个标识符。
operator(操作符)
: A control operator or a redirection operator. See [[#Redirections|Redirections]], for a list of redirection operators. Operators contain at least one unquoted metacharacter.
: 一个控制操作符或者一个重定向符。参看[[#Redirections|Redirections]](重定向操作列表)。 操作符包括至少一个未引用元字符。
process group(进程组)
: A collection of related processes each having the same process group ID.
: 相关进程的集合,它们有相同的进程组ID。
process group ID(进程组ID)
: A unique identifier that represents a process group during its lifetime.
: 一个进程组在它的生命期内的一个唯一的标识。
reserved word(保留字)
: A word that has a special meaning to the shell. Most reserved words introduce shell flow control constructs, such as for and while.
: 一个对shell有特定意义的词。多数保留字与shell流程控制结构相关,例如for以及while。
return status(返回状态)
: A synonym for exit status.
: 退出状态(exit status)的同义词。
signal(信号)
: A mechanism by which a process may be notified by the kernel of an event occurring in the system.
: 一种机制,通过这种机制系统内核中发生的事件可以通知到一个进程。
special builtin(特殊内置指令)
: A shell builtin command that has been classified as special by the POSIX standard.
: 也是shell的内置指令, 它被POSIX标准分类为特殊。
token(令牌)
: A sequence of characters considered a single unit by the shell. It is either a word or an operator.
: 一个字符序列,它被shell认为是一个单位。它也是一个词或一个操作符。
word(词)
: A sequence of characters treated as a unit by the shell. Words may not include unquoted metacharacters.
: 一个字符序列,它被shell认为是一个单位。词无法包含或引用一个元字符。


=Basic Shell Features=
=Basic Shell Features=
Bash is an acronym for ‘Bourne-Again SHell’. The Bourne shell is the traditional Unix shell originally written by Stephen Bourne. All of the Bourne shell builtin commands are available in Bash, The rules for evaluation and quoting are taken from the POSIX specification for the ‘standard’ Unix shell.
Bash是‘Bourne-Again SHell’的首字母缩写。Bourne shell是传统Unix shell,它诞生之初是有Stephen Bourne写就的。所有Bourne shell的内置命令在Bash中都是可用的,其评估和引用规则取自POSIX规范的Unix shell ‘standard’。
This chapter briefly summarizes the shell’s ‘building blocks’: commands, control structures, shell functions, shell ''parameters'', shell expansions, ''redirections'', which are a way to direct input and output from and to named files, and how the shell executes commands.
本章简述了shell的‘building blocks’(构造块):命令、控制结构、shell函数、shell ''参数'', shell 扩展, ''redirections''(重定向),它是一种基于命名文件的直接输入和输出方法,以及shell怎样执行命令。
{| style="border: none" width="100%"
|-
| width="200px" | [[#Shell Syntax|Shell Syntax]]:
| What your input means to the shell.
对shell来说你输入的是什么?
|-
| [[#Shell Commands|Shell Commands]]:
| The types of commands you can use.
你可以使用的命令。
|-
| [[#Shell Functions|Shell Functions]]:
| Grouping commands by name.
按名称分组的命令。
|-
| [[#Shell Parameters|Shell Parameters]]:
| How the shell stores values.
shell如何存储值。
|-
| [[#Shell Expansions|Shell Expansions]]:
| How Bash expands parameters and the various expansions available.
Bash如何扩展参数以及可用的扩展。
|-
| [[#Redirections|Redirections]]:
| A way to control where input and output go.
控制输入和输出地的方法。
|-
| [[#Executing Commands|Executing Commands]]:
| What happens when you run a command.
当你运行一个命令时发生了什么?
|-
| [[#Shell Scripts|Shell Scripts]]:
| Executing files of shell commands.
shell命令的执行文件。
|}
==Shell Syntax==
{| style="border: none" width="100%"
|-
| width="120px" | [[#Shell Operation|Shell Operation]]:
| The basic operation of the shell. 
shell的基本操作。
|-
| [[#Quoting|Quoting]]:
| How to remove the special meaning from characters.
如何删除字符的特殊含义。
|-
| [[#Comments|Comments]]:
| How to specify comments.
如何指定注释。
|}
When the shell reads input, it proceeds through a sequence of operations. If the input indicates the beginning of a comment, the shell ignores the comment symbol (‘#’), and the rest of that line.
当shell读取输入时,它是按照一定顺序的操作来完成的。如果输入始于一个注释,则shell将忽略改行注释符号("#")及其后的字符。
Otherwise, roughly speaking, the shell reads its input and divides the input into words and operators, employing the quoting rules to select which meanings to assign various words and characters.
其他方面,大约的说,shell读取输入并且把输入内容分成字(words)和操作符(operators),通过引用规则来选各不同的种含义被指派到不同的字(words)和字符(characters)。
The shell then parses these tokens into commands and other constructs, removes the special meaning of certain words or characters, expands others, redirects input and output as needed, executes the specified command, waits for the command’s exit status, and makes that exit status available for further inspection or processing.
然后shell解析这些令牌(tokens)为命令和其他结构,之后移除某些字或字符的特殊意义,其他扩展也包括:根据需要重定向输入和输出,执行指定的指令,等待命令的退出状态,并且让合格退出状态对于其他检查和处理是可用的。
===Shell Operation===
The following is a brief description of the shell’s operation when it reads and executes a command. Basically, the shell does the following:
以下是当shell读取或执行一个命令时所进行操作的的一个简要描述,shell将做以下事情:
# Reads its input from a file (see [[#Shell Scripts|Shell Scripts]]), from a string supplied as an argument to the -c invocation option (see [[#Invoking Bash|Invoking Bash]]), or from the user’s terminal.
#: 从文件读取它的输入(参看[[#Shell Scripts|Shell Scripts]]),从字符串参数以-c调用选项方式(参看[[#Invoking Bash|Invoking Bash]]),或者从用户终端。
# Breaks the input into words and operators, obeying the quoting rules described in [[#Quoting|Quoting]]. These tokens are separated by metacharacters. Alias expansion is performed by this step (see [[#Aliases|Aliases]]).
#: 断句,把相关的输入分解成words和操作符,它遵循[[#Quoting|Quoting]]中的引用规则。这些tokens会被元字符分开。别名扩展将按照[[#Aliases|Aliases]]步骤被执行。
# Parses the tokens into simple and compound commands (see [[#Shell Commands|Shell Commands]]).
#: 这些tokens将被解析为一些简单和复合的命令(参看[[#Shell Commands|Shell Commands]])。
# Performs the various shell expansions (see [[#Shell Expansions|Shell Expansions]]), breaking the expanded tokens into lists of filenames (see [[#Filename Expansion|Filename Expansion]]) and commands and arguments.
#: 执行不同的shell扩展(参看[[#Shell Expansions|Shell Expansions]]),断句这些扩展的tokens为文件列表(参看[[#Filename Expansion|Filename Expansion]])命令及参数。
# Performs any necessary redirections (see [[#Redirections|Redirections]]) and removes the redirection operators and their operands from the argument list.
#: 执行任何必要的重定向(参看[[#Redirections|Redirections]])并且从参数列表中移除那些重定向操作符和它们的操作数。
# Executes the command (see [[#Executing Commands|Executing Commands]]).
#: 执行命令(参看[[#Executing Commands|Executing Commands]])。
# Optionally waits for the command to complete and collects its exit status (see [[#Exit Status|Exit Status]]).
#: 可选的,等待命令的完成并收集器退出状态(参看[[#Exit Status|Exit Status]])。
===Quoting===
====Escape Character====
====Single Quotes====
====Double Quotes====
====ANSI-C Quoting====
====Locale-Specific Translation====
===Comments===

2016年7月4日 (一) 09:42的最新版本

本文引自https://www.gnu.org/software/bash/manual/bash.html.

Bash特性

This text is a brief description of the features that are present in the Bash shell (version 4.3, 2 February 2014). The Bash home page is http://www.gnu.org/software/bash/.

这部分文字是当前Bash shell(版本4.3, 2014年2月)特性的一个简要描述。Bash的主页是http://www.gnu.org/software/bash/.

This is Edition 4.3, last updated 2 February 2014, of The GNU Bash Reference Manual, for Bash, Version 4.3.

此4.3版本更新于2014年2月,它的GNU Bash参考手册也是针对此4.3版本。

Bash contains features that appear in other popular shells, and some features that only appear in Bash. Some of the shells that Bash has borrowed concepts from are the Bourne Shell (sh), the Korn Shell (ksh), and the C-shell (csh and its successor, tcsh). The following menu breaks the features up into categories, noting which features were inspired by other shells and which are specific to Bash.

Bash所涵盖的一些特性也出现在其他流行的shells中。Bash的有些概念来自于其他的一些shells例如Bourne Shell(sh)、Korn Shell (ksh)以及C-shell(csh及其后继者,如tcsh)。以下菜单把这些特性进行了分类,并且不刻意哪些特性来自于其他的shells或者哪些特性来自于某个特定的Bash。

This manual is meant as a brief introduction to features found in Bash. The Bash manual page should be used as the definitive reference on shell behavior.

本手册意图扼要介绍Bash中的特性。本Bash手册应作为shell的引用参考来使用。

Introduction: An introduction to the shell.

shell介绍。

Definitions: Some definitions used in the rest of this manual.

手册中使用的一些定义。

Basic Shell Features: The shell "building blocks".

shell”构造块”

Shell Builtin Commands: Commands that are a part of the shell.

shell指令。

Shell Variables: Variables used or set by Bash.

Bash中使用的变量。

Bash Features: Features found only in Bash.

Bash独有特性。

Job Control: What job control is and how Bash allows you to use it.

什么是作业控制已经Bash中如何允许使用作业控制。

Command Line Editing: Chapter describing the command line editing features.

命令行编辑功能的章节描述。

Using History Interactively: Command History Expansion

指令历史增强

Installing Bash: How to build and install Bash on your system.

如果在你的系统中建造和安装Bash。

Reporting Bugs: How to report bugs in Bash.

如何报告Bash中的Bug。

Major Differences From The Bourne Shell: A terse list of the differences between Bash and historical versions of /bin/sh.

一个简洁列(/bin/sh)表以介绍Bash历史版本的不同。

GNU Free Documentation License: Copying and sharing this documentation.

拷贝及共享此文档。

Indexes: Various indexes for this manual.

此手册的个中索引。

Introduction

What is Bash?

Bash is the shell, or command language interpreter, for the GNU operating system. The name is an acronym for the 'Bourne-Again SHell', a pun on Stephen Bourne, the author of the direct ancestor of the current Unix shell sh, which appeared in the Seventh Edition Bell Labs Research version of Unix.

Bash是shell,或者,对于GUN操作系统而言它也叫做指令语言解释器。这个名字源于"Bourne-Again SHell"的首字母缩写,Stephen Bourne的双关语,其直接始祖源自当前Unix shell sh,它始现于贝尔实验室Unix的第七个版本。

Bash is largely compatible with sh and incorporates useful features from the Korn shell ksh and the C shell csh. It is intended to be a conformant implementation of the IEEE POSIX Shell and Tools portion of the IEEE POSIX specification (IEEE Standard 1003.1). It offers functional improvements over sh for both interactive and programming use.

Bash在很大程度上与sh是兼容的,并且它也从Korn shell ksh以及C shell csh纳入了一些有用的功能。它的目的是成为IEEE POSIX Shell的一致实现,以及IEEE POSIX规范(IEEE Standard 1003.1)的工具部分。他提供了sh针对交互及编程方面的功能改善。

While the GNU operating system provides other shells, including a version of csh, Bash is the default shell. Like other GNU software, Bash is quite portable. It currently runs on nearly every version of Unix and a few other operating systems - independently-supported ports exist for MS-DOS, OS/2, and Windows platforms.

在GNU操作系统提供其他shells时,包括csh的一个版本,Bash是缺省的shell。如同其他GNU软件,Bash是非常便携的。它几乎允许于每一个版本的Unix以及其他一些操作系统 - 基于端口提供独立支持如MS-DOS,OS/2以及Windows平台。

What is a shell?

At its base, a shell is simply a macro processor that executes commands. The term macro processor means functionality where text and symbols are expanded to create larger expressions.

于其基础,shell是一个简单的用于执行指令的宏处理器。宏处理器这个术语意味着这样的功能,那里一些文本和符号可被扩展成为更大的表达式。

A Unix shell is both a command interpreter and a programming language. As a command interpreter, the shell provides the user interface to the rich set of GNU utilities. The programming language features allow these utilities to be combined. Files containing commands can be created, and become commands themselves. These new commands have the same status as system commands in directories such as /bin, allowing users or groups to establish custom environments to automate their common tasks.

Unix shell既是一个指令解释器也是一种编程语言。作为指令解释器,shell针对丰富的GUN工具提供了用户接口。而它的编程语言特性又允许这些工具可被组合起来。包含指令的文件可以被创建,而它们又成为指令的一部分。这些新指令与在其他目录中的系统指令有着相同的地位例如/bin,并允许用户或组去建立客户环境或自动化他们的公共任务。

Shells may be used interactively or non-interactively. In interactive mode, they accept input typed from the keyboard. When executing non-interactively, shells execute commands read from a file.

Shells的使用可以是交互或非交互的。在交互模式下,它们接受键盘输入。在非交互执行时, shells执行可从文件读取。

A shell allows execution of GNU commands, both synchronously and asynchronously. The shell waits for synchronous commands to complete before accepting more input; asynchronous commands continue to execute in parallel with the shell while it reads and executes additional commands. The redirection constructs permit fine-grained control of the input and output of those commands. Moreover, the shell allows control over the contents of commands’ environments.

一个shell允许一同步和异步两种方式执行GNU指令。对于同步指令shell等待以完成更多的输入;对于异步指令shell执行读或其它指令是并发执行的。重定向构造允许一更细的粒度控制指令的输入和输出。而且,shell允许支配指令环境的内容。

Shells also provide a small set of built-in commands (builtins) implementing functionality impossible or inconvenient to obtain via separate utilities. For example, cd, break, continue, and exec cannot be implemented outside of the shell because they directly manipulate the shell itself. The history, getopts, kill, or pwd 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 in subsequent sections.

Shells也针对那些不可能或不方便获得的第三方工具提供了少量内置指令(嵌入部件)的功能实现。例如:cd,break,continue以及exec等无法再shell外部实现因为它们直接操纵shell自己。历史上getopts、kill或pwd等嵌入组件,及其他可以被分别实现为不同工具,但是作为内置的指令,它们更方便一些。所有这些shell嵌入部件后面的章节还将介绍。

While executing commands is essential, most of the power (and complexity) of shells is due to their embedded programming languages. Like any high-level language, the shell provides variables, flow control constructs, quoting, and functions.

当必须执行指令时,shells的强大或复杂之处应归结于它们的嵌入式编程语言。如同其他任何高级语言,shell提供变量、流程控制结构、引用已经函数等功能。

Shells offer features geared specifically for interactive use rather than to augment the programming language. These interactive features include job control, command line editing, command history and aliases. Each of these features is described in this manual.

Shells提供的特性特别适合交互使用而非增加编程语言。这些交互特性包括作业控制、命令行编辑、命令历史记录和别名。所有这些特性都将在本手册中叙述。

Definitions

These definitions are used throughout the remainder of this manual.

这些定义将在本手册的其余部分使用到。

POSIX(可移植操作系统接口)

A family of open system standards based on Unix. Bash is primarily concerned with the Shell and Utilities portion of the POSIX 1003.1 standard.
基于Unix家族的一个开放系统标准。Bash主要关心POSIX 1003.1标准的Shell以及工具部分。

blank

A space or tab character.
一个空格(space)或制表符(tab)。

builtin(内建/嵌入)

A command that is implemented internally by the shell itself, rather than by an executable program somewhere in the file system.
一个由shell自己内部实现的的命令,它不是一个存储于文件系统中的可执行程序。

control operator(控制操作符)

A token that performs a control function. It is a newline or one of the following: ‘||’, ‘&&’, ‘&’, ‘;’, ‘;;’, ‘|’, ‘|&’, ‘(’, or ‘)’.
一个记号并执行一个控制功能。它是一个换行符或以下东东:‘||’, ‘&&’, ‘&’, ‘;’, ‘;;’, ‘|’, ‘|&’, ‘(’, or ‘)’。

exit status(退出状态)

The value returned by a command to its caller. The value is restricted to eight bits, so the maximum value is 255.
由命令返回该值到它的调用者。此值限于一个8比特值,所以它的最大值是255。

field(字段)

A unit of text that is the result of one of the shell expansions. After expansion, when executing a command, the resulting fields are used as the command name and arguments.
一个文本单位是该shell扩展的结果。扩展之后,当执行一个命令时,这个结果字段被用作命令名或参数。

filename

A string of characters used to identify a file.
由字符组成的字符串用于识别一个文件。

job(作业)

A set of processes comprising a pipeline, and any processes descended from it, that are all in the same process group.
由一组操作组成的操作流水,它的任何后裔操作均属于同一个操作组。

job control(作业控制)

A mechanism by which users can selectively stop (suspend) and restart (resume) execution of processes.
一套机制,用户可以选择性地停止和重启操作的执行。

metacharacter(元字符)

A character that, when unquoted, separates words. A metacharacter is a blank or one of the following characters: ‘|’, ‘&’, ‘;’, ‘(’, ‘)’, ‘<’, or ‘>’.
当一个字符,当它未被引号引用,或者是单独出现。一个元字符可以是一个空格或以下单个出现的字符:‘|’,‘&’,‘;’,‘(’, ‘)’,‘<’ 或者 ‘>’。

name(名称)

A word consisting solely of letters, numbers, and underscores, and beginning with a letter or underscore. Names are used as shell variable and function names. Also referred to as an identifier.
一个仅由字母、数字及下划线组成的词,名字被用于shell的变量及函数名称。也被认为是一个标识符。

operator(操作符)

A control operator or a redirection operator. See Redirections, for a list of redirection operators. Operators contain at least one unquoted metacharacter.
一个控制操作符或者一个重定向符。参看Redirections(重定向操作列表)。 操作符包括至少一个未引用元字符。

process group(进程组)

A collection of related processes each having the same process group ID.
相关进程的集合,它们有相同的进程组ID。

process group ID(进程组ID)

A unique identifier that represents a process group during its lifetime.
一个进程组在它的生命期内的一个唯一的标识。

reserved word(保留字)

A word that has a special meaning to the shell. Most reserved words introduce shell flow control constructs, such as for and while.
一个对shell有特定意义的词。多数保留字与shell流程控制结构相关,例如for以及while。

return status(返回状态)

A synonym for exit status.
退出状态(exit status)的同义词。

signal(信号)

A mechanism by which a process may be notified by the kernel of an event occurring in the system.
一种机制,通过这种机制系统内核中发生的事件可以通知到一个进程。

special builtin(特殊内置指令)

A shell builtin command that has been classified as special by the POSIX standard.
也是shell的内置指令, 它被POSIX标准分类为特殊。

token(令牌)

A sequence of characters considered a single unit by the shell. It is either a word or an operator.
一个字符序列,它被shell认为是一个单位。它也是一个词或一个操作符。

word(词)

A sequence of characters treated as a unit by the shell. Words may not include unquoted metacharacters.
一个字符序列,它被shell认为是一个单位。词无法包含或引用一个元字符。

Basic Shell Features

Bash is an acronym for ‘Bourne-Again SHell’. The Bourne shell is the traditional Unix shell originally written by Stephen Bourne. All of the Bourne shell builtin commands are available in Bash, The rules for evaluation and quoting are taken from the POSIX specification for the ‘standard’ Unix shell.

Bash是‘Bourne-Again SHell’的首字母缩写。Bourne shell是传统Unix shell,它诞生之初是有Stephen Bourne写就的。所有Bourne shell的内置命令在Bash中都是可用的,其评估和引用规则取自POSIX规范的Unix shell ‘standard’。

This chapter briefly summarizes the shell’s ‘building blocks’: commands, control structures, shell functions, shell parameters, shell expansions, redirections, which are a way to direct input and output from and to named files, and how the shell executes commands.

本章简述了shell的‘building blocks’(构造块):命令、控制结构、shell函数、shell 参数, shell 扩展, redirections(重定向),它是一种基于命名文件的直接输入和输出方法,以及shell怎样执行命令。

Shell Syntax: What your input means to the shell.

对shell来说你输入的是什么?

Shell Commands: The types of commands you can use.

你可以使用的命令。

Shell Functions: Grouping commands by name.

按名称分组的命令。

Shell Parameters: How the shell stores values.

shell如何存储值。

Shell Expansions: How Bash expands parameters and the various expansions available.

Bash如何扩展参数以及可用的扩展。

Redirections: A way to control where input and output go.

控制输入和输出地的方法。

Executing Commands: What happens when you run a command.

当你运行一个命令时发生了什么?

Shell Scripts: Executing files of shell commands.

shell命令的执行文件。

Shell Syntax

Shell Operation: The basic operation of the shell.

shell的基本操作。

Quoting: How to remove the special meaning from characters.

如何删除字符的特殊含义。

Comments: How to specify comments.

如何指定注释。

When the shell reads input, it proceeds through a sequence of operations. If the input indicates the beginning of a comment, the shell ignores the comment symbol (‘#’), and the rest of that line.

当shell读取输入时,它是按照一定顺序的操作来完成的。如果输入始于一个注释,则shell将忽略改行注释符号("#")及其后的字符。

Otherwise, roughly speaking, the shell reads its input and divides the input into words and operators, employing the quoting rules to select which meanings to assign various words and characters.

其他方面,大约的说,shell读取输入并且把输入内容分成字(words)和操作符(operators),通过引用规则来选各不同的种含义被指派到不同的字(words)和字符(characters)。

The shell then parses these tokens into commands and other constructs, removes the special meaning of certain words or characters, expands others, redirects input and output as needed, executes the specified command, waits for the command’s exit status, and makes that exit status available for further inspection or processing.

然后shell解析这些令牌(tokens)为命令和其他结构,之后移除某些字或字符的特殊意义,其他扩展也包括:根据需要重定向输入和输出,执行指定的指令,等待命令的退出状态,并且让合格退出状态对于其他检查和处理是可用的。

Shell Operation

The following is a brief description of the shell’s operation when it reads and executes a command. Basically, the shell does the following:

以下是当shell读取或执行一个命令时所进行操作的的一个简要描述,shell将做以下事情:

  1. Reads its input from a file (see Shell Scripts), from a string supplied as an argument to the -c invocation option (see Invoking Bash), or from the user’s terminal.
    从文件读取它的输入(参看Shell Scripts),从字符串参数以-c调用选项方式(参看Invoking Bash),或者从用户终端。
  2. Breaks the input into words and operators, obeying the quoting rules described in Quoting. These tokens are separated by metacharacters. Alias expansion is performed by this step (see Aliases).
    断句,把相关的输入分解成words和操作符,它遵循Quoting中的引用规则。这些tokens会被元字符分开。别名扩展将按照Aliases步骤被执行。
  3. Parses the tokens into simple and compound commands (see Shell Commands).
    这些tokens将被解析为一些简单和复合的命令(参看Shell Commands)。
  4. Performs the various shell expansions (see Shell Expansions), breaking the expanded tokens into lists of filenames (see Filename Expansion) and commands and arguments.
    执行不同的shell扩展(参看Shell Expansions),断句这些扩展的tokens为文件列表(参看Filename Expansion)命令及参数。
  5. Performs any necessary redirections (see Redirections) and removes the redirection operators and their operands from the argument list.
    执行任何必要的重定向(参看Redirections)并且从参数列表中移除那些重定向操作符和它们的操作数。
  6. Executes the command (see Executing Commands).
    执行命令(参看Executing Commands)。
  7. Optionally waits for the command to complete and collects its exit status (see Exit Status).
    可选的,等待命令的完成并收集器退出状态(参看Exit Status)。

Quoting

Escape Character

Single Quotes

Double Quotes

ANSI-C Quoting

Locale-Specific Translation

Comments