变量加载文件基础概念
两种方式解释:
看书
目录 内容
变量 变量值
小学算术题
x+1=5 x=4
已知变量=数值
变量=变量值
1)设置变量的方法(临时生效)
[root@hgg ~]# x=1234
[root@hgg ~]# echo $x
1234
2、脚本概念
将多个命令整合在一个文件
通过执行加载一个文件可以完成多件事
1)脚本文件:永久生效(hgg.sh)
[root@hgg ~]# vi hgg.sh
dir=hgg
mkdir /$dir/hgg01
mkdir /$dir/hgg02
mkdir /$dir/hggo3
~
root@hgg ~]# sh hgg.sh
[root@hgg ~]# ls /hgg
hgg01 hgg02 hggo3
2)变量信息和别名信息配置文件(PATH)
/etc/profile文件 == /etc/brashrc
作用:
01、设置环境变量信息和程序启动相关的信息,为登录之后的系统环境做准备
02、可以配置函数和别名功能 最好配置在/etc/brashrc
03、让变量信息永久生效
直接让文件生效的方法:source /etc/profile
系统中变量的类型:
普通变量:需要人为设置的变量,简化脚本的编写
环境变量:系统默认就有的变量
a.环境变量PATH的作用:
[root@hgg ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@hgg ~]# which cat -- 查看cat命令的路径
/usr/bin/cat
[root@hgg ~]# ls /hgg
hgg01 hgg02 hggo3
[root@hgg ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.201 hgg01.com
[root@hgg ~]# mv /usr/bin/cat /hgg
[root@hgg ~]# ls /usr/bin/cat
ls: cannot access /usr/bin/cat: No such file or directory
[root@hgg ~]# cat /etc/hosts
-bash: /usr/bin/cat: No such file or directory
•
b.修改PATH环境变量的方法:
临时修改:
[root@hgg ~]# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/hgg
永久设置:
vi /etc/profile
在最后一行加入以下内容:
export