Understanding and learning of shell programming Basics Bash_linux Shell

Source: Internet
Author: User
Tags locale

1. Understanding Bash

Through the shell will input the instructions and kernel communication, let kernel control hardware work
View Shell:cat/etc/shell
A preset shell type is recorded in the/etc/passwd after login and is related to the account
Command alias: Alias lm= ' Ls-al ' #注意有无空格
Help: Man bash
Command types: Type

Copy Code code as follows:

Type ls # ls is aliased to ' Ls–color=auto '
Type Cat # cat is hashed (/BIN/CAT)
Type CD # CD is a shell builtin


Command execution:

\[enter]: Escapes [Enter], presses and does not execute, but is a different line

2, the shell's variable function

Concept: The same variable, different users can have different values, so you can use variables to represent this value without having to write a specific value to the program, such as $path

Copy Code code as follows:

Display variables: Echo $PATH
Set Variable: path=xxx #注意空格有无
Extension variable: path= $PATH: XXX
Cancel variable: unset MAIL
View Environment variables: env
Viewing environment variables and custom variables: set

PS1: Prompt character setting
Custom variable to environment variable: Export
Why to turn to environment variables: Because subroutines inherit the environment variables of the parent program
Language support
View system supported languages: LOCALE-A
To view language-related variables: locale
Keyboard read user input Read:read atest #将用户输入读入atest变量
Declaring variable types declare:declare-i sum=100+50

3. Command alias and History command

Alias

Copy Code code as follows:

Alias lm= ' Ls-al | More
Unalias LM

History command

Copy Code code as follows:

History

4, Bash Shell's operating environment

Lookup Order when instruction executes
Relative/absolute path-> alias-> bash built-in-> $PATH
Bash configuration file

Copy Code code as follows:

Login Shell/non-login Shell
Login Shell: You need to enter your account password when entering the shell
Non-login Shell: Login via graphical interface, then start shell without entering account password

Configuration file

Copy Code code as follows:

Login Shell:
/etc/profile: System Overall setting
The following three files are read in order, if present, and no longer read later
~/.bash_profile
~/.bash_login
~/.profile

Wildcard characters

Copy Code code as follows:

*: 0 To infinity characters
? : a character
[]: [ABC] # A or B or C
[-]: [0-9] # 0 to 9
[^]: [^ABC] # is not a character of a,b,c

5, Data Flow redirect

Copy Code code as follows:

>: Covering
>>: Cumulative
/dev/null: Receive information but not display
Sequential execution: CMD1,CMD2,CMD3
Based on the results of the previous article, determine the next
CMD1 && CMD2
cmd1 | | Cmd2

6, Pipeline command

Copy Code code as follows:

ls | Less
Cut: Same Row data split
echo $PATH | Cut-d ': ' F 5 #以 ': ' Split, 5th data
grep: Returns this line if the required information is available on a line
Sort: Sorting
Uniq: Repeating content is displayed only once
WC: Count the number of words
Tee: Bidirectional redirection
TR: deleting or replacing data
Col: converting to plain text
Join: Bring related information from two files together
Paste: Put two lines together and separate them in the middle with [Tab]
Expand: Convert [Tab] to space
Split: Transfer large files to small files

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.