1 What shell?
Shell is a scripting language
You can use logical judgments, loops, and other syntax
Functions can be custom-defined
The shell is a collection of system commands
Shell scripts enable automated operations, which can greatly increase our operational efficiency
2 shell script structure and execution methods
Need to add #!/bin/bash at the beginning
Lines that begin with # are interpreted as explanatory notes
The name of the script ends with. SH and is used to differentiate between this is a shell script
There are two methods of executing
chmod +x 1.sh; ./1.sh
bash 1.sh
View the script execution process
bash -x 1.sh
To see if the script is syntactically incorrect
bash -n 1.sh
3 Date Command usage
date +%F 年月日 2018-05-14 等价于 date +%Y-%m-%ddate +%T 时分秒 22:45:23 等价于 date +%H:%M:%Sdate +%Y 四位表示的年份 2018date +%y 两位表示的年份 18date +%m 月份date +%M 分钟date +%d 日date +%D 月日年 05/14/18date +%H 时date +%h 月份 5月date +%M 分date +%S 秒date +%s 绝对时间戳 距离1970.1.1. 00:00:00 多少秒date -d @1504620492 时间转换date -d "+1day" 一天后date -d "-1 day" 一天前date -d "-1 month" 一月前date -d "-1 min" 一分钟前date +%w 星期几date +%W 第几周
4 Variables in the script
You should use a variable instead when you use a string more frequently in your script and the string length is long
When using conditional statements, variables are often usedif [ $a -gt 1 ]; then ... ; fi
Replace n= ' Wc-l 1.txt ' with a variable when referencing the result of a command
When writing and user interaction scripts, variables are also essential for read-p "Input a number:" N; Echo $n If you don't write this n, you can use $reply directly.
Built-in variables $, $ $, $ ... $ $ represents the script itself, the first parameter, the $ A second ... $ #表示参数个数
Mathematical Operation a=1;b=2; c=$ (($a + $b)) or $[$a + $b]
Linux Learning Summary (57) Shell Script 1