Shell--bash Environment

Source: Internet
Author: User
Tags aliases

First, what is the shell

The shell typically represents two levels of meaning, one is the command interpreter, such as bash, and the other is the shell script. In this section we stand on the command interpreter's point of view to illustrate the shell

Ii. priority of the command

The commands are divided into:

==> Alias

==> Compound Commands

==> function

==> build_in

==> Hash

==> $PATH

==> Error:command not found

Alias alias: Aliases command is to simplify the integration of output to a long parameter command, alias definition method aliases la= ' Ls-al ' Alias Unalias la

Buildin Internal command: It is the command function of bash comes simple, the help of internal command in BUILTIN (1)

External command: is a small program exists in/bin//sbin//usr/bin and other places, the source code installed software add environment variables should be changed path.

Three, meta characters

Metacharacters (as explained by the shell)

``

command in exchange for command execution results

[[email protected] ~]# ls
4.txt anaconda-ks.cfg a.txt B.txt c.txt D.txt nginx-1.10.3 nginx-1.10.3.tar.gz
[[email protected] ~]# res= ' ls ' #取命令的运行结果, assign to variable res
[Email protected] ~]# echo $res #查看变量res的值
4.txt anaconda-ks.cfg a.txt B.txt c.txt D.txt nginx-1.10.3 nginx-1.10.3.tar.gz

$

$ variable Value

[Email protected] ~]# money=10
[Email protected] ~]# echo $money
10
[Email protected] ~]# echo 00000$money
0000010
[Email protected] ~]# echo $money 0000

[Email protected] ~]# echo ${money}0000
100000
$[] integer calculation echo $[2+3]-*/% floating point with echo "scale=3; 10/3 "| Bc-l

${}

Range of variable names

$()

With ', but it makes up for ' nesting flaws

[Email protected] ~]# res= ' echo ' ls ' #嵌套使用后无法达到预想的效果: Take the effect of the Echo pile file name.

[Email protected] ~]# echo $res
Ls

[Email protected] ~]# res=$ (echo $ (LS)) #替代方案
[Email protected] ~]# echo $res
4.txt anaconda-ks.cfg a.txt B.txt c.txt D.txt nginx-1.10.3 nginx-1.10.3.tar.gz

~

Home Directory

[Email protected] tmp]# CD ~
[Email protected] ~]# pwd
/root

!

Take Non-

[Email protected] ~]# LS/DEV/SDA
SDA SDA1 Sda2
[[email protected] ~]# ls/dev/sda[0123]
/dev/sda1/dev/sda2
[[email protected] ~]# ls/dev/sda[!01]
/dev/sda2

History command Invocation

[Email protected] ~]#!343
Hostname
Miwifi-r3-srv

Match last History command

[Email protected] ~]#!ls
LS/DEV/SDA[!01]
/dev/sda2

! LS with a space to reverse the return value of the command

[[email protected] ~]# echo OK
Ok
[[email protected] ~]# echo $? #上一条命令执行的结果, 0 for execution success, not 0 for execution failure
0
[[email protected] ~]#! echo OK #将结果取反
Ok
[[email protected] ~]# echo $?
1

0-255, 0 is true, not 0-bit false

@

No special meaning

#

# Notes

%

Kill the background process, the jobs number; Take the mold

^

Take the non-and! Identical

[[email protected] ~]# ls/dev/sda[^01]
/dev/sda2
[[email protected] ~]# ls/dev/sda[!01]
/dev/sda2

Replace

[Email protected] ~]# systemctl Restart Network
[Email protected] ~]# ^network^sshd^
Systemctl Restart sshd

&

Background execution

&&

Logic and

*

Match any length string; compute multiplication

()

Executing in a child process

[Email protected] ~]# x=1
[Email protected] ~]# (x=666)
[Email protected] ~]# echo $x
1
[Email protected] ~]#
[Email protected] ~]# (X=666;echo $x)
666

-

A minus sign; an interval; CD-

_

No special meaning

+

Plus

=

Assign value

|

Pipeline

||

Logical OR

\

Translated

[[email protected] test]# echo \ \
\
[[email protected] test]# echo \ '

[[email protected] test]# echo "'"

{}

Command list, note that the beginning and end of parentheses must be a space {ls; }

[]

Word wildcard match, matching one of the parentheses inside

: null Command truth

[Email protected] ~]#:
[[email protected] ~]# echo $?
0

Multiple commands can be received: Ls;pwd;echo 123; Whether right or wrong, will continue to the last command

“”

"" soft-quoted characters in quotes make sense

[Email protected] test]# x=1
[[email protected] test]# echo "$x" #双引号的代表软引用, special characters in quotation marks have special meanings, such as $, ' etc.
1
[[email protected] test]# echo ' $x ' #单引号代表硬引用, all characters in quotes have no special meaning
$x

’‘

' Hard cited, all characters in quotation marks have no special meaning

<

< input redirection

>

> Output redirection

>>

>> Append

<<

<< here Document

>&

>& merging 2 and 1 outputs

,

, enumerate separators

. Source

. source; Current directory

/

/directory Separators

?

? Single character

? Wildcard characters: any character

Enter

Enter command execution

*

* Wildcard characters: any character

One of the [ABC] list items

[^ABC] can also use the range [A-z] for the list to represent the aabbcc...,[0-9] for the 012345 ...

{}

{} Loop List

[[email protected] test]# Touch {1..3}{a ... D}.txt
[[email protected] test]# ls
1a.txt 1b.txt 1c.txt 1d.txt 2a.txt 2b.txt 2c.txt 2d.txt 3a.txt 3b.txt 3c.txt 3d.txt

Range of control variable names echo ${ab}c

Shell--bash Environment

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.