Shell basic application

Time:2020-4-6

What is shell?

Shell is the interpreter program between you and the user suddenly in Linux, usually referring to bash, which is responsible for translating and communicating user / program instructions to the kernel

How to use shell:

1. interactive execution instruction: manual intervention, low execution efficiency

2. Non interactive execution instruction: it is executed quietly in the background with high efficiency and easy to write script

Cat / etc / shell to see all the explanations of this machine

Yum – y install KSH install a new interpreter

Advantages of Bash

Add alias shortcut key history command pipeline redirection

Script shell specification

1. Declaration interpreter

    #!/bin/bash

2. Notes, which can explain script function, variable function, etc

3. Execution code

+x authority

Execute directly with interpreter, execute with new interpreter (start subprocess)

Execute with source (or. + space) command, execute with current interpreter (do not open subprocess) / / source test01.sh

Deploy Yum warehouse script:

!/bin/bash

Deploying yum

echo “[adc]

name=adc

baseurl=http://content.example.com/rh…_64/dvd

enabled=1

gpgcheck=0″ > /etc/yum.repos.d/adc.repo

Digital currency http://www.gendan5.com/digita

Deploy FTP script:

!/bin/bash

yum -y install vsftpd &> /dev/null

systemctl restart vsftpd

 systemctl enable vsftpd

Constants: fixed

Variable: flexible and variable, script can use multiple variables to increase performance

Types of variables

1. Custom variable

The process of defining variable value with variable name = variable value is called assignment. The definition of name can use case letters, numbers, underscores, cannot start with numbers, and cannot use special symbols

A = 20 / / define variable

Echo $a / / call variable

a1=20

1A = 20 / / definition failed

a_1=20

A $= 20 / / definition failed

a=40

echo $a RMB

Unset A / / undefine variables

environment variable

Uid current user ID user current user name shell current user’s interpreter hostname home current user’s home directory PWD location path where the command is stored

PS1 first level prompt PS2 second level prompt

Extended application of variables

“” scope

” define scope, shield special symbols

`’apostrophe, you can get the command execution result = = $()

Stty – echo / / mask echo

Stty echo / / restore echo

a=20

Export a local variable – > global variable

Export – n a global variable – > local variable

Calculation

Method 1

expr 1   +   1 

expr 1   –   1 

expr 1   /   1 

Expr 1 \ * 1 1 ‘*’ 1 \ special meaning of a character after escape symbol mask

Expr 5% 2 > > > 1 modulus, remainder

Method two

echo $[ 1+1]

echo$[a+a]

Method three

Let operation result is not displayed, which is usually used to define the value of variable or increase or decrease the value of variable

let a++

let a–

let a+=2

let a-=2

Method four

BC calculator, can calculate decimal

echo 1.15+5.04 | bc

Echo scale = 3; 10 / 3 | BC / / scale defines the decimal places

Recommended Today

PHP Basics – String Array Operations

In our daily work, we often need to deal with some strings or arrays. Today, we have time to sort them out String operation <?php //String truncation $str = ‘Hello World!’ Substr ($STR, 0,5); // return ‘hello’ //Chinese string truncation $STR = ‘Hello, Shenzhen’; $result = mb_ Substr ($STR, 0,2); // Hello //First occurrence of […]