1、 脚本的命名 *.sh 仅仅是在颜色上发生了变化,需要修改权限
2、 命名变量
1)自定义变量:
name=zhangsan 变量也是弱类型的
2)#env
大写字母
3)$
#echo $name
#echo $PATH 环境变量
4)变量的作用域
默认的情况下用户自定义变量为——局部
可以通过调用多个shell进程
打开shell——父
再次打开shell——子
shell----------子
#env
SHLVL==shell level
注意:shell的层次
#export 声明全局变量
5){}
#name=zhangsan
#echo{$name}isastudent 花括号的作用分清变量和字母
6) > >> 输出 一个表示覆盖,一个表示追加
定向 重定向
< << 输入
<<:指定终止的符号
#cat <&0 表示接受来自键盘的输入
#cat <file 表示接受来自文件的输入
at <file -m
系统在接受输入输出内容存在方向
一般方向都有默认值
< :从右侧接受输入
输入输出描述符号:
输入:键盘 0
输出:屏幕 1
错误输出: 分离 2
临时符号——起过渡作用3-9 他们是文件的描述符
LS 2>/dev/null ——虚拟出来的一个设备 把错误信息扔掉 (黑洞)
string = <<<HELLO 三个表示后面紧邻的符号表示结束标志
操作演示:
# cd /home
# ls
dir1 dir2 dir4 file1 file3 file6 hao yum
dir_1 dir3 file file2 file5 file7 wei
# LS
bash: LS: command notfound
# ls -l file2>&1
-rw-r--r-- 1 root root 14 12月 12 09:38 file2
# ls -l file2
-rw-r--r-- 1 root root 14 12月 12 09:38 file2
# LS
bash: LS: command notfound
# LS 2>/dev/null
# LS 2>&1
bash: LS: command notfound
# cat
zhanghua wrfee
zhanghua wrfee
# cat <&0
ksadfg
ksadfg
fsdggfsdgg
# LS 3<&23>&1
bash: LS: command notfound
# LS 3<&23>file
bash: LS: command notfound
# touch file
# ls
dir1 dir2 dir4 file1 file3 file6 hao yum
dir_1 dir3 file file2 file5 file7 wei
# LS 3<&23>file
bash: LS: command notfound
# cat file
# LS 3<&23>&1
bash: LS: command notfound
# LS 2>file
# cat file
bash: LS: command notfound
# LS 3<&23>file
bash: LS: command notfound
cat<<AB
> af
> dfsdfd
> dfdsgsd
> gdsgfsdfsdfdf
> AB
af
dfsdfd
dfdsgsd
gdsgfsdfsdfdf
# cat<<AB >file
> abce
> afd
> AB
# cat file
abce
afd
# cat<<A >file.sh
> #!/bin/bash
> echo"hello"
> A
# cat file.sh
#!/bin/bash
echo "hello"
# sh file.sh
hello