First, Introduction
The shell is the command-line interpreter that the user interacts with the operating system.
There are many kinds of shells:
bash, csh, sh, ksh 、、、
The command line we saw when we waited for Linux was a bash.
Two, the first script:
[Email protected] script]# vim first.sh
#!/bin/bash
#auther: Xiaofan
#time: 2016.10.4
#井号是注释
echo "Hello word"
Execute script:
Method 1:
[Email protected] script]# bash first.sh
Hello Word
[Email protected] script]# sh first.sh
Hello Word
Method 2:
[Email protected] script]# chmod +x first.sh
[Email protected] script]#./first.sh
Hello Word
To view the script execution process:
[Email protected] script]# sh-x first.sh
+ echo ' Hello word '
Hello Word
Third, variable
There are two main categories of variables:
Local variables: You need to define them yourself.
Environment variables: The system comes with.
Variable definition:
Variable name = variable Value
To invoke a custom variable:
[Email protected] script]# name= "Xiaofan"
[Email protected] script]# echo "My name is $name"
My name is Xiaofan
[Email protected] script]# echo my name is $name
My name is Xiaofan
[Email protected] script]# echo ' My name is $name ' #注意单引号是不会解释变量的
My name is $name
Common system Variables:
[email protected] script]# cat t1.sh
#!/bin/bash
Echo #当前程序名
echo $ #程序的第一个参数
Echo $* #程序的所有参数名
Echo $# #当前程序的参数个数
echo $? #程序执行的返回状态
Echo $PATH #系统环境变量的路径
Echo $PWD #当前目录
Echo $UID #当前用的id
[Email protected] script]# sh t1.sh t1 T2
t1.sh
T1
T1 T2
2
0
/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/root/bin
/script
0
Third, the script output color font:
\033[32m and \033[0m fonts will turn green.
All the fonts below \033[32m and \033[1m will turn green.
Shell Summary (0 basic primer)