shell 环境变量

环境变量

  • 特点
    • linux 系统创建
    • 大写
    • linux大部分地方都可以使用
  • 查看所有环境变量
    • env
    • export
    • declare

#HISTSIZE    HISTFILESIZE 
[root@manager ~]# export HISTSIZE=10
 [root@manager ~]# 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 
 
[root@manager ~]# export HISTFILESIZE=15 
[root@manager ~]# 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 
[root@manager ~]# export HISTCONTROL=ignorespace 
[root@manager ~]# echo 654321 |passwd --stdin oldboy
 更改用户 oldboy 的密码 。
 passwd:所有的身份验证令牌已经成功更新。
 [root@manager ~]# 
 [root@manager ~]# 
 [root@manager ~]# 
 [root@manager ~]# 
 [root@manager ~]#    echo 111111  |passwd --stdin oldboy 
 更改用户 oldboy 的密码 。
 passwd:所有的身份验证令牌已经成功更新。
  [root@manager ~]# 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
 
[root@manager ~]# export PROMPT_COMMAND="date"
 2020年 01月 08日 星期三 12:23:24 CST 
 [root@manager ~]# 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
[root@manager ~]# oldboy=666 
[root@manager ~]# echo $oldboy 666
[root@manager ~]# env |grep oldboy 
[root@manager ~]# #export 变量  变量成为环境变量
[root@manager ~]# export oldboy=666 
[root@manager ~]# env |grep oldboy oldboy=666

环境变量相关的文件和目录
在这里插入图片描述

[root@manager ~]#cat /etc/profile.d/show.sh
#!/bin/bash
#author: oldboy
echo  oldboyedu.com

[root@manager ~]# 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
[root@manager ~]# tail  -1  /etc/profile /etc/bashrc   ~/.bashrc  ~/.bash_profile 
tail: 在未定义环境中的无效选项 -- 1 
[root@manager ~]# 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
发布了58 篇原创文章 · 获赞 52 · 访问量 1240

猜你喜欢

转载自blog.csdn.net/ljaixiaoxue/article/details/104007597