Creation and execution of a script
1. Create file *.sh, file suffix sh
2. Editing scripts
The first line must be: #!/bin/bash #指定解释脚本的shell
3. Empowering
chmod u+x a.sh
4. Implementation
./a.sh
Variables in the two shell scripts
1. Definition and deletion of variables
Name= "Hello" #定义变量 = cannot have spaces before and after
unset name #删除变量
A. Variables defined in the current shell are valid only in the current shell
B. Whether it is a normal variable or an environment variable, in the final analysis is a variable, all follow the basic operation of the variable
2. Environment variables
(1) View all environment variables: set/env
(2) To view the environment variables associated with the specified process
Pgrep Process_name #获取应用程序的进程号
Cat/proc/process_num/environ #根据进程号获取相关环境变量
(3) Increase and modification of environment variables
Introduction to environment variables
Http://www.cnblogs.com/techroad4ca/p/5068549.html
3. References to variables
Add $ symbol To reference variable value before variable
Cases:
Echo $USER
Name=hello
echo $name # "Hello"
N1=name
N2= $name
echo N1 n2 # "name" "Hello"
Linux Shell 01 Scripts and variables