初识shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# 脚本第一行指定那个解释器来执行
# Date:
# Author:
# Blog:
# Description:
# Version:


#查看默认shell
echo $SHELL
grep root /etc/passwd

#增加vi别名
alias vi='vim'
echo "alias vi='vim'" >> /etc/profile
source /etc/profile

# 查看bash版本
bash --version

# 检查bash是否存在漏洞
env x='() { :;}; echo be careful' bash -c "echo this is test"

# 升级bash方法
yum -y update bash

# shell脚本执行加载环境变量顺序
/etc/profile > ~/.bash_profile > ~/.bashrc > /etc/bashrc

# shell脚本运行几种方式
# 1、bash test.sh
# 2、chmod +x test.sh
# ./test.sh
# 3、source test.sh或. test.sh
# 第三种可以将test.sh脚本变量值或函数返回值传递到当前父shell脚本中使用
# 而不是产生一个子shell来执行

# 例如
# cat test.sh
# #!/bin/bash
# user=`whoami`

# bash test.sh
# echo $user
# echo $user 输出的值是?


# 变量
# 环境变量(全局变量)
# 普通变量(局部变量)

# 环境变量命名 一般采用大写形式
# 定义环境变量并赋值3种方法
export LOGDIR="/home/wwwlogs"
declare -x LOGDIR="/home/wwwlogs"
LOGDIR="/home/wwwlogs" ;export LOGDIR

# 自定义全局变量
# 编辑/etc/profile 添加
export LOGDIR="/home/wwwlogs"

# 配置用户环境变量 一般配置~/.bashrc或~/.bashrc_profile文件
# 配置全局环境变量 一般配置/etc/profile或、/etc/bashrc或/etc/profile.d/(登录后初始化或加载内容)

# 配置登录提示
# 1、cat /etc/motd 这里仅能配置字符串内容
# 2、在/etc/profile.d/下增加脚本
# cat /etc/profile.d/ropon.sh
# echo "this is login testing!"
# name="pengge"
# echo $name

# 查看环境变量
# echo $HOME
# printf "$HOME\n"

# 取消本地变量及环境变量的值
# unset HOME

# 登录Linux系统时,shell会作为登录shell启动,此时加载变量顺序
/etc/profile > ~/.bash_profile > 操作bash

_______ ~/.bashrc

____ /etc/profile.d/*.sh < /etc/bashrc


/etc/locale.conf