Shell Programming (v) Bash features

Source: Internet
Author: User

Bash features


Terminal, the interface program attached to the terminal:

Gui:kde, GNome, XFCE

Cli:/etc/shells

Bash

Zsh

Fish


Features of bash:

Command line expansion: ~, {}

Command aliases: Alias, Unalias

Command history: Historical

File name wildcard: Glob

Shortcut keys: Ctrl + A, E, U, K, l

Command completion: $PATH

Path Completion:


Bash features: command hash

Cache the results of previous commands: Key-value

Key: Search Key

Value: Values


Hash command:

Hash: List

hash-d COMMAND: Delete

Hash-r: Empty


Features of bash: variables

Program: Instruction + data

Directives: provided by program documents;

Data: IO devices, files, pipelines, variables


Program: algorithm + data structure

Data?


Variable name + point to memory space


Variable assignment: Name=value

Variable types: Storing formats, representing data ranges, participating operations

Programming Languages:

Strongly typed variables

Weakly typed variables:

Bash sees all variables as character types;

The variables in bash do not have to be declared in advance, equivalent to the declaration and assignment process at the same time;

Declaration: Type, variable name

Variable substitution: Replace the position of the variable name with the data in the memory space it points to;

Variable reference: ${var_name}, $var _name

Variable name: Variable name can only contain numbers, letters and underscores, and cannot start with a number;

Variable name: See the name, the naming mechanism follows a certain rule, and cannot use the reserved words of the program, such as if, else, then, while and so on;

Bash Variable type:

Local variable: Scope is only the current shell process;

Environment variable: scope is the current shell process and its child processes;

Local variables: Scope is only a fragment of code (function context);


Positional parameter variables: parameters passed to the shell process executing the script;

Special variables: Shell-built variables with special functions;

$?:

0: Success

1-255: Failure


Local variables:

Variable assignment: Name=value

Variable reference: ${name}, $name

"": The variable name is replaced with its value;

': The variable name is not replaced with its value;

View variables: Set

Undo Variable: unset name

Note: Here is a non-variable reference;


Environment variables:

Variable assignment:

(1) Export Name=value

(2) Name=value

Export name

(3) Declare-x Name=value

(4) Name=value

Declare-x Name

Variable reference: ${name}, $name


Note: Bash has many environment variables embedded in it (usually all uppercase characters) to define the work environment for bash

PATH, Histfile, Histsize, Histfilesize, Histcontrol, SHELL, HOME, UID, PWD, oldpwd


View environment variables: Export, Declare-x, PRINTENV, env

Undo environment variable: unset name


Read-only variables:

(1) Declare-r name

(2) readonly name


Read-only variables cannot be re-assigned, and revocation is not supported; The lifetime is the life cycle of the current shell process and terminates with the shell process terminating;


Bash features multi-command execution:

~]# COMMAND1; COMMAND2; COMMAND3; ...


Logical operation:

Operand: True (true, yes, on, 1)

False (False, no, off, 0)


And:

1 && 1 = 1

1 && 0 = 0

0 && 1 = 0

0 && 0 = 0

Or:

1 | | 1 = 1

1 | | 0 = 1

0 | | 1 = 1

0 | | 0 = 0

Non -:

! 1 = 0

! 0 = 1

XOR:


Short Circuit rule:

~]# COMMAND1 && COMMAND2

COMMAND1 is "false", then COMMAND2 will not be executed;

Otherwise, COMMAND1 is "true", then COMMAND2 must be executed;


~]# COMMAND1 | | COMMAND2

COMMAND1 is "true", then COMMAND2 will not be executed;

Otherwise, COMMAND1 is "false", then COMMAND2 must be executed;


Example: ~]# ID $username | | Useradd $username


Shell Programming (v) Bash features

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.