shell 环境变量
程序员文章站
2022-04-29 23:33:21
...
环境变量
- 特点
- linux 系统创建
- 大写
- linux大部分地方都可以使用
- 查看所有环境变量
- env
- export
- declare
#HISTSIZE HISTFILESIZE
[aaa@qq.com ~]# export HISTSIZE=10
[aaa@qq.com ~]# history
991 echo "$PATH $(hostname) `whoami` {1..5}"
992 echo $PATH $(hostname) `whoami` {1..5}
993 echo $PATH $(hostname) `whoami` {1..5} *
994 env
995 export
996 declare
997 export TMOUT=3
998 history
999 export HISTSIZE=10
1000 history
[aaa@qq.com ~]# export HISTFILESIZE=15
[aaa@qq.com ~]# cat ~/.bash_history echo
$_oldboy
oldbing=666
echo $oldbing
oldbing=爱生活 爱冰冰
oldbing="爱生活 爱冰冰"
echo $oldbing
cd
echo '$PATH $(hostname) `whoami` {1..5}'
echo "$PATH $(hostname) `whoami` {1..5}"
echo $PATH $(hostname) `whoami` {1..5}
echo $PATH $(hostname) `whoami` {1..5} *
env export declare export TMOUT=3
#HISTCONTROL
[aaa@qq.com ~]# export HISTCONTROL=ignorespace
[aaa@qq.com ~]# echo 654321 |passwd --stdin oldboy
更改用户 oldboy 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[aaa@qq.com ~]#
[aaa@qq.com ~]#
[aaa@qq.com ~]#
[aaa@qq.com ~]#
[aaa@qq.com ~]# echo 111111 |passwd --stdin oldboy
更改用户 oldboy 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[aaa@qq.com ~]# history
1003 ll -h ~/.bash_history
1004 less ~/.bash_history
1005 export HISTFILESIZE=15
1006 cat ~/.bash_history
1007 cat -n ~/.bash_history
1008 echo 123456 |passwd --stdin oldboy
1009 history
1010 export HISTCONTROL=ignorespace
1011 echo 654321 |passwd --stdin oldboy
1012 history
#PROMPT_COMMAND
[aaa@qq.com ~]# export PROMPT_COMMAND="date"
2020年 01月 08日 星期三 12:23:24 CST
[aaa@qq.com ~]# ls -l
总用量 27408
drwxr-xr-x 3 root root 4096 12月 20 15:45 ansible_playbook
drwxr-xr-x 3 root root 133 12月 18 08:48 ansible-project1
drwxr-xr-x 15 root root 266 12月 24 10:22 ansible_role
-rw-r--r-- 1 root root 27998103 12月 23 12:39 ansible_role_2019-12-23.zip
drwxr-xr-x 2 root root 4096 12月 23 09:52 ansible_tasks
drwxr-xr-x 4 root root 4096 12月 20 15:59 ansible_variables
-rw-r--r-- 1 root root 37621 12月 19 17:20 ansible_variableszip.zip
-rw-r--r-- 1 root root 105 12月 23 11:43 sshkey.sh
-rw-r--r-- 1 root root 610 12月 24 09:48 student.txt
-rw-r--r-- 1 root root 368 12月 24 09:49 yj.sh
**创建环境变量**
```bash
[aaa@qq.com ~]# oldboy=666
[aaa@qq.com ~]# echo $oldboy 666
[aaa@qq.com ~]# env |grep oldboy
[aaa@qq.com ~]# #export 变量 变量成为环境变量
[aaa@qq.com ~]# export oldboy=666
[aaa@qq.com ~]# env |grep oldboy oldboy=666
环境变量相关的文件和目录
[aaa@qq.com ~]#cat /etc/profile.d/show.sh
#!/bin/bash
#author: oldboy
echo oldboyedu.com
[aaa@qq.com ~]# head -2 /etc/profile /etc/bashrc ~/.bashrc ~/.bash_profile
==> /etc/profile <==
# /etc/profile
echo /etc/profile start
==> /etc/bashrc <==
# /etc/bashrc
echo /etc/bashrc start
==> /root/.bashrc <==
# .bashrc
==> /root/.bash_profile <==
# .bash_profile
[aaa@qq.com ~]# tail -1 /etc/profile /etc/bashrc ~/.bashrc ~/.bash_profile
tail: 在未定义环境中的无效选项 -- 1
[aaa@qq.com ~]# tail -n1 /etc/profile /etc/bashrc ~/.bashrc ~/.bash_profile
==> /etc/profile <==
echo /etc/profile end
==> /etc/bashrc <==
echo /etc/bashrc end
==> /root/.bashrc <==
echo ~/.bashrc end
==> /root/.bash_profile <==
echo ~/.bash_profile end