Shell basic application


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


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

Deploy Yum warehouse script:


Deploying yum

echo “[adc]




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

Digital currency

Deploy FTP script:


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


1A = 20 / / definition failed


A $= 20 / / definition failed


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


Export a local variable – > global variable

Export – n a global variable – > local variable


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]


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 […]