• Nenhum resultado encontrado

Pocket Reference

N/A
N/A
Protected

Academic year: 2023

Share "Pocket Reference"

Copied!
132
0
0

Texto

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. Finally, references to the form name (N) refer to the man page for name in the N section of the online manual (accessed via the man command).

Eventually, the feature set of the Korn shells surpassed that of the Bourne and C shells, while remaining compatible with the former for shell programming. The Free Software Foundation, in keeping with its goal of producing a complete Unix-like system, developed a clone of the Bourne shell, written from scratch, called "Bash", Bourne-Again Shell. Over time, Bash has become a POSIX-compliant version of the shell with many additional features that overlap with those of the Korn shell, but Bash is not an exact clone of the Korn shell.

Overview of Features

Invoking the Shell

Options

Output from built-in commands goes to file descriptor 1; all other shell output goes to file descriptor 2.

Arguments

Syntax

Special Files

Filename Metacharacters

Bash supports the POSIX notation [[=c=]] for matching characters of equal weight and [[.c.]] for specifying comparison sequences.

Brace Expansion

In addition, character classes, of the form [[:class:]], allow you to match the following character classes. On modern systems, strings like [D-R] are not portable; the system locale may include more than just the uppercase letters D through R in the range. The shell expands them to the full range between start and end, increasing by incr if provided.

For numeric expansion, start or end or both may be preceded by one or more leading zeros. The results of expansion are padded with zeros to the maximum of the widths of start and end. Brace expansion is executed before other expansions, and the opening and closing braces must not be quoted for Bash to recognize them.

Quoting

Command Forms

Redirection Forms

Simple redirection

Redirection using file descriptors

Multiple redirection

Send standard output and cmd error output through pipe to tee to standard output (usually terminal) and to files. Most other shells require special syntax or don't offer this feature at all.

Process substitution

Special filenames

The following sorts the two files and displays the differences between the results using the diff: command.

Functions

According to the POSIX standard, any redirects given with the function definition are evaluated when the function is executed, not when it is defined. Signal-based traps Shared until the function redefines the trap DEBUG Not shared unless function tracing is enabled. EXIT Shared until the function redefines the trap RETURN Not shared unless function tracing is enabled.

Variables

Variable Assignment

The += operator allows you to add or append the right side of the assignment to an existing value. Integer variables treat the right-hand side as an expression, which is evaluated and added to the value.

Variable Substitution

Built-in Shell Variables

If this variable exists in the environment when Bash starts, it sets the indicated options before running any startup files. Each element refers to a command in the internal hash table maintained by the hash command. The key, or final key in a sequence, that caused the current termination function to be called.

GROUPS Array variable containing the list of numeric group IDs of which the current user is a member. PIPESTATUS Array variable containing the exit statuses of the commands in the most recent pipeline in the foreground. Many of these variables support either the Bash Debugger (see http://bashdb.sourceforge.net) or for programmable completion (see the section "Programmable Completion" on page 41).

Other Shell Variables

SECONDS[=n] Number of seconds since the shell started, or if n is specified, number of seconds since the assignment + n. If set in the environment at startup, Bash enables each option in the list before reading startup files. HISTCONTROL=list Colon-separated list of values ​​that determine how commands are stored in the history file.

HISTTIMEFORMAT=string A format string for strftime(3) to use for printing timestamps along with commands from the history command. If set (even null), Bash stores timestamps in the history file along with the commands. HOSTFILE=file Name of a file in the same format as /etc/hosts that Bash should use to find hostnames for hostname completion.

Arrays

The first character signals a story event, the second is the "quick replace" character, and the third indicates the start of a comment.

Indexed arrays

This is not necessary when referencing strings inside (( )) (the letter form that does automatic quoting).

Associative arrays

Special Prompt Strings

Arithmetic Expressions

Operators

Command History

Line-Edit Mode

Common editing keystrokes

The fc Command

Shell–Style History

Event designators

Word substitution

History modifiers

Programmable Completion

Programmable completion lets you, as a shell programmer, write code to customize the list of possible completions that Bash will offer for a particular partially entered word. You specify, via various options, how to adjust the list of possible completions for the specific command. COMPREPLY is an array into which the function places the final list of completion results.

Also within the code for an -F function, you can use the compgen command to generate a list of results, such as. If a pathname is used, Bash checks to see if a compspec exists for the full pathname. Otherwise, it sets the command name to the last component of the pathname, and looks for a comp spec for the command name.

From this list, only those that complete the word as a prefix are used for the list of possible completions. For the -d and -f options, the variable FIGNORE is used to filter out unwanted matches. Also, for both functions and commands, $1 is the name of the command whose arguments are being completed.

2 is the word being completed and $3 is the word before the word being completed. By prefixing the pattern with a !, the meaning is reversed, and the pattern instead specifies that only matching files should be kept in the list. An & in the pattern is replaced with the text of the word being filled.

On the other hand, if -o plusdirs is supplied, Bash adds the result of directory completion to the previously generated list.

Job Control

Shell Options

Verify that commands found in the hash table still exist before attempting to use them. When an attempt is made to exit a shell and there are stopped or running background jobs, the shell prints Therearerunningjobs. Make the < and > operators of the [[ ]] command ignore the locale when doing string comparison.

Make the < and > operators of the [[ ]] command ignore the locale when doing string comparison. Interactive shells will not terminate in such a case, regardless of the setting of this option. When a command is run by the DEBUG trap inside a shell function or script fetched with . dot) or the source returns with an exit status of 2, the shell simulates a call to return.

When completing, ignore words that match the suffix list in FIGNORE, even if such words are the only possible completions. Append the history list to a file named $HISTFILE on exit instead of overwriting the file. Allow the user to re-edit a failed csh-style history replacement with the readline library.

Put the results of csh-style history replacement into the readline library's edit buffer instead of running it directly, in case the user wants to edit it further. If cmdhist is also set, save multiline commands to the history file with newlines instead of semicolons. If you use readline, don't search $PATH when a completion is attempted on an empty line, or a line consisting solely of whitespace.

Expand patterns that do not match any files to the null string instead of using the literal pattern as an argument.

Command Execution

If the command cannot be found, if there is a function named command_not_found_handle, the shell will call it and pass the command words as arguments to the function. This difference, combined with the command command, makes it possible to write functions that override built-in shells such as cd. If Bash quits due to receiving a SIGHUP, or if the huponexit shell option is set, Bash will send a SIGHUP to all running child tasks.

Coprocesses

Restricted Shells

Built-in Commands

The options are the same as those accepted by declare; see statement on page 68 for the full list. Rotate the stack so that the counting point from the left, as shown by dirs, is the new top of the stack. Rotate the stack so that the counting element from the right, as shown by dirs, is the new top of the stack.

Options provide control over the use of logical versus physical processing of the printed path. Exit the function with status n or with the exit status of the previously executed command. If a valid item number is entered, the shell sets x to the selected value and executes commands.

With no arguments, set prints the values ​​of all variables known to the current shell. The exact behavior is complex; see “set -e Details” on page 97, later in this entry. Do not read $ENV or $BASH_ENV, do not import functions from the environment, and ignore the values ​​of the BASHOPTS, CDPATH, GLOBIGNORE, and SHELLOPTS variables.

Each option must be one of the shell option names for set-o, instead of the options listed in “Shell Options” on page 47. Same as -a, for POSIX compatibility.) -file file exists and is a regular file. gfile file exists, and its set-group-id bit is set. Gfile file exists, and its group is the effective group ID. hfile file exists and is a symbolic link.

A list of signal names, numbers and meanings was given in the kill record on page 83.

Resources

Online Resources

Books

Acknowledgments

Index

Symbols

Referências

Documentos relacionados

Ao que parece, depois da morte do professor Eduar- do Thomaz Colville, o ensino da Língua Inglesa foi também dispensado da Academia de Marinha, pois, com o Decreto de 9 de março