Dian What is a shell?
Shell is in linux you suddenly and interpreter between the user program, commonly referred to as bash, the kernel is responsible for translation and would like to convey user / program instructions
Shell to use:
1. Interactive executes instructions: human intervention, low efficiency.
2. Non-interactive execution of instructions: quietly in the background, high efficiency, easy to write the script.
cat / etc / shell see all explanation of the machine
yum -y install ksh install new interpreter
bash advantage
Alias Shortcuts tab filled pipe redirection command history
Shell scripts to write specification
1. Declare Interpreter
#!/bin/bash
2. Notes, can explain the role of scripting functions, variables, etc.
3. Code Execution
+ X permissions
Directly executed by an interpreter, performed using the new interpreter (open sub-process)
Use source (or + Space) command execution, execution (do not open the sub-process) // source test01.sh using the current interpreter
Yum warehouse deployment script:
#!/bin/bash
#部署yum
echo "[adc]
name=adc
baseurl=http://content.example.com/rhel7.0/x86_64/dvd
enabled=1
gpgcheck=0" > /etc/yum.repos.d/adc.repo
Ftp script deployment:
#!/bin/bash
yum -y install vsftpd &> /dev/null
systemctl restart vsftpd
systemctl enable vsftpd
Constants: constant
Variables: flexible, multi-use script variables can increase performance
The type of a variable
1. Custom Variables
Variable name = value of the process variable values define the variable assignment is called, the name can be defined case letters, numbers, underscores, not begin with a number, a special symbol can not be used
a = 20 // definition of variables
echo $ a // variable call
a1 = 20
1a = 20 // definition of failure
a_1=20
a $ = 20 // definition of failure
a=40
echo $a RMB
unset a // variable definitions canceled
Environment Variables
UID of the current user ID USER the current user name SHELL user's current location interpreter HOSTNAME hostname HOME directory of the current user's home directory where PATH store PWD command position
Prompt a prompt PS1 PS2 two
Extended application variables
"" Define the scope
'' Defining the scope of the shield special symbols
`` Anti-apostrophe, you can get command execution result == $ ()
stty -echo // echo shield
stty echo // echo recovery
a=20
export a local variable -> Global Variables
export -na global variables -> local variables
Compute
method one
expr 1 + 1
expr 1 - 1
expr 1 / 1
expr 1 \ * 1 1 '*' 1 \ special meaning after a shield escape character symbol
expr 5% 2 >>>> 1 modulo take the remainder
Method Two
echo $[ 1+1]
echo $ [a + a]
Method Three
let operation is not displayed, the value commonly used for the calculation result is defined variable or variables to decrease from
let a++
let a--
let a+=2
let a-=2
Method Four
bc calculator, you can calculate decimal
echo 1.15+5.04 | bc
echo scale = 3; 10/3 | bc // scale defined after a few decimal points