Walk into the computer on the 11th day (some simple usages of the shell)

Source: Internet
Author: User
Tags arithmetic operators clear screen control characters posix printable characters alphanumeric characters egrep

The properties of a bash
Some of the parameters of their own properties are stored in bash, enabling or turning off a feature
For example, control *. Whether the character is a wildcard
View parameter Set-o
Close the Noglob parameter
Set-o Noglob
LS *
LS: *: no file or directory

Set +o Noglob
LS *

Curing settings
The change variables properties we learned earlier, and so on, are restored to the default values after the machine restarts in memory.
So how do you cure these settings to make them permanent?
This requires an understanding of bash two types
1. Login Shell 2. Non-login shell
Login Shell
is by entering the user name password or Su-the shell obtained by
The non-login shell is a shell environment that is opened with bash commands and scripts
So what's the difference between them? What does it have to do with our curing setup?
We know that everything is a file in Linux, and the Shell's attribute loading is also written to the file.
The contents of the corresponding file are loaded at login to initialize the shell environment.
The difference between a non-login and a login is that the loaded file is different, resulting in a different shell environment
Let's see if the login shell loads those files.
-/etc/profile
-/etc/profile.d/*.sh
-$HOME/.bash_profile
-$HOME/.BASHRC
-/ETC/BASHRC
Then look at the files loaded by the non-login shell
-$HOME/.BASHRC
-/ETC/BASHRC
-/etc/profile.d/*.sh
Visible, the non-login shell loads a lot less files
Then we want to cure a configuration when the login is in effect, it is obvious to know which file to write.
In general, we will set environment variables in the $HOME/.bash_profile
If the variable you want to use regardless of the login is set in the $HOME/.BASHRC

Command Completion TAB key
Simplified input tips to prevent writing errors

Historical records
Up and down key check
History Query with!id call
Ctrl+r input Match

Shortcut keys
CTRL + A header
Ctrl+e End of Line
Ctrl+u Delete from cursor to beginning string
Ctrl+k Delete from cursor to line end string
Ctrl+l Clear Screen

Two what is the regular

1 regular is a way to describe a character or a string by combining symbols with special meanings, called regular expressions. Or a rule used to describe a class of things.

2 in Linux, wildcard characters are interpreted by the shell, while regular expressions are interpreted by commands.

Triple grep Command

1 Related parameters

-N: Show line numbers

-O: Show only matching content

-Q: Silent mode, no output, you have to use $? To determine the success of the execution, that is, there is no filtering to the desired content

-L: If the match succeeds, only the file name is printed, the failure is not printed, usually-rl together, grep-rl ' root '/etc

-A: If the match is successful, the matching row and the subsequent n rows are printed together

-B: If the match succeeds, the matching row and its first n rows are printed together

-C: If the match succeeds, the matching row and its n rows are printed together

--color
-C: If the match succeeds, the number of rows to match is printed

-e: Equals Egrep, extended

-I: Ignore case

-V: Inverse, mismatch

-W: Match word

2 Types of grep

Grep
Fgrep
Pgrep
Egrep

3 Regular Introduction

^ Beginning of the line
$ End of line
. Any single character other than the line break
* 0 or more of the leading characters
. * All Characters
[] Any character within a group of characters
[^] reverse each character within a character group (does not match each character in a group of characters)
^[^] lines that begin with characters within a non-character group
[A-z] lowercase letter
[A-z] capital letters
[A-z] lowercase and uppercase letters
[0-9] Number
\< words are usually separated by spaces or special characters, and successive strings are treated as words.
\> Word Tail

Extended regular sed plus-r parameter or escape
grep plus-E or egrep or escaped
AWK directly supports but does not contain {n,m}
You can use--posix support
awk '/ro{1,3}/{print} '/etc/passwd
awk--posix '/ro{1,3}/{print} '/etc/passwd
Sed-n '/roo\?/p '/etc/passwd
Sed-rn '/roo?/p '/etc/passwd
? A leading character 0 or one
+ Leading character one or more
ABC|DEF ABC or DEF
A (Bc|de) f ABCF or Adef
x\{m\} X appears m times
x\{m,\} X appears m times to multiple times (at least m times)
x\{m,n\} X appears m times to N times
POSIX-defined character classification

[: Alnum:] alphanumeric characters. The
Match range is [a-za-z0-9]
[: Alpha:] alphabetic characters.
The match range is [a-za-z]
[: blank:] Space or tab characters.
The match range is a space and the TAB key
[: Cntrl:] Control characters.
Match control keys such as ^m to press CTRL + V and press ENTER to output
[:d igit:] Numeric characters.
Match all numbers [0-9]
[: graph:] characters that is both printable and visible. (A space is the print-
able, but not visible, while an A is both.)
Match all visible characters without spaces and tab is all the symbols you can see with your eyes on your keyboard in a text document
[: Lower:] lower-case alphabetic characters.
lowercase [A-z]
[:p rint:] Printable characters (characters that is not control characters.)
Match all visible characters including spaces and tab
to all symbols printed on the paper
[:p UNCT:] punctuation characters (characters that is not letter, digits, con- Trol characters, or space characters).
Special input symbol +-=) (*&^%$#@!~ ' |\ "' {}[]:;? />.<,
Note that it does not contain spaces and tab
This collection does not equal ^[a-za-z0-9]
[: space:] space characters (such as space, tab, and FormFeed, to n Ame a few).

[: Upper:] Upper-case alphabetic characters.
uppercase [A-z]
[: Xdigit:] Characters that is hexadecimal digits.
16 binary number [0-f]

How to use:
[[email protected] ~]# grep--color ' [[: Alnum:]] '/etc/passwd

Four variables

1 Why there are variables

The operation of a program is a variable of some column state, which is represented by the change of variable value.

2 variable naming rules

Start with a letter or underscore, and the rest can be: letters, numbers, underscores.

It is advisable to follow the following specifications:

(1). Start with a letter
(2). Use an underscore or underline to make a connection to a word
(3). The same type is distinguished by numbers
(4). For the best file plus extension
For example: Sql_bak.tar.gz,log_bak. tar.bz2

3 System Variables

Set and env differences
Set: Show All variables
ENV: Environment variables

4 Assigning values to variables

Varname=value
Echo $VARNAME
Delete variable unset VARNAME

5 Common system Variables

PATH
Pwd
Lang
HOME
Histsize
PS1
Ifs
The field separator is a space, wrapping, TAB key collection

6 Global variables and local variables

gender= ' Male ' #在爹这个位置定义一个局部变量gender
Export money=1000 #在爹这个位置定义一个全局变量money
Bash #切换到子bash
echo $gender #在儿子这里看它爹的局部变量gender, results are empty, not seen

echo $money #在儿子这里看它爹的全局变量money and you can see
Export hobby= ' Piao ' #在儿子这里定义一个全局变量hobby
Exit #退出, go into Dad's bash environment
Echo $hobby #爹是看不到儿子的export的, son's son can see

7 Defining the bounds of a variable name

Rest_mem=20
Echo ${rest_mem}%
20%

8 Data types

The variables in bash do not have to be declared, they are used. The default variables are character types, and you can have numeric types, normal scripts, both of which are sufficient.

Five operators

1 arithmetic operators

+

-

*

/

%

Echo $[3+1]
4

2 Relationship Operations

With (())

<

>

<=

>=

==

!=

&&

||

Test command related, [] can achieve the same effect
X=1
[$x-GT 1]
echo $?
0

Walk into the computer on the 11th day (some simple usages of the shell)

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.