自学基础1_linux_4_理解环境变量
2015-05-18 11:47
288 查看
本章将详细讲解linux环境变量配置
查出系统支持的所有shell:$cat /etc/shells
系统默认shell:echo $0 或者 ps -p $$
用户级环境变量:
临时切换shell(子shell): 目标shell名
退回父shell:exit
查看嵌套层级,也既子shell数量:
想要把当前系统shell从bash永久换成zsh?试试这个:
想把其他用户的shell从bash永久换成ksh?试试这个:
http://blog.jobbole.com/85702/
环境变量给谁用?
什么是环境?
谁来管理环境?
环境给谁用?
什么时候用?
怎么用?
如何设置环境变量?
如何让环境变量生效?
source 或者 . 配置文件
如何清除环境变量?
如何查看环境变量?
env
下面是bash shell里一些常见变量的列表:
。。。。
改动影响较大的变量:
printenv env_name
echo $env_name
bashrc与profile的区别
要搞清bashrc与profile的区别,首先要弄明白什么是交互式shell和非交互式shell,什么是login shell 和non-login shell。
交互式模式就是shell等待你的输入,并且执行你提交的命令。这种模式被称作交互式是因为shell与用户进行交互。这种模式也是大多数用户非常熟悉的:登录、执行一些命令、签退。当你签退后,shell也终止了。 shell也可以运行在另外一种模式:非交互式模式。在这种模式下,shell不与你进行交互,而是读取存放在文件中的命令,并且执行它们。当它读到文件的结尾,shell也就终止了。
bashrc与profile都用于保存用户的环境信息,bashrc用于交互式non-loginshell,而profile用于交互式login shell。系统中存在许多bashrc和profile文件,下面逐一介绍:
/etc/pro此文件为系统的每个用户设置环境信息,当第一个用户登录时,该文件被执行.
并从/etc/profile.d目录的配置文件中搜集shell的设置.
/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取。有些linux版本中的/etc目录下已经没有了bashrc文件。
~/. pro每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该
文件仅仅执行一次!默认情况下,它设置一些环境变量,然后执行用户的.bashrc文件.
~/.bashrc:该文件包含专用于某个用户的bash shell的bash信息,当该用户登录时以及每次打开新的shell时,该文件被读取.
另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是"父子"关系.
某网友总结如下:
/etc/profile,/etc/bashrc 是系统全局环境变量设定
~/.profile,~/.bashrc用户家目录下的私有环境变量设定
当登入系统时候获得一个shell进程时,其读取环境设定档有三步
1首先读入的是全局环境变量设定档/etc/profile,然后根据其内容读取额外的设定的文档,如
/etc/profile.d和/etc/inputrc
2然后根据不同使用者帐号,去其家目录读取~/.bash_profile,如果这读取不了就读取~/.bash_login,这个也读取不了才会读取
~/.profile,这三个文档设定基本上是一样的,读取有优先关系
3然后在根据用户帐号读取~/.bashrc
至于~/.profile与~/.bashrc的不区别
都具有个性化定制功能
~/.profile可以设定本用户专有的路径,环境变量,等,它只能登入的时候执行一次
~/.bashrc也是某用户专有设定文档,可以设定路径,命令别名,每次shell script的执行都会使用它一次
一、Linux的变量种类
按变量的生存周期来划分,Linux变量可分为两类:
1、永久的:需要修改配置文件,变量永久生效。
2、临时的:使用export命令声明即可,变量在关闭shell时失效。
http://www.cnblogs.com/Neddy/archive/2011/03/01/1968018.html
命令补齐:http://blog.163.com/card_2005/blog/static/1178103682009104103811868/
参考文档:http://blog.csdn.net/flowingflying/article/details/5014914
http://www.blogjava.net/jasmine214--love/archive/2010/11/26/339108.html http://blog.csdn.net/aaaaatiger/article/details/1713611 运算符
"Why is
separate file from
then? This is done for mostly historical reasons, when machines were extremely slow compared to today's workstations. Processing the commands in
take quite a long time, especially on a machine where a lot of the work had to be done by external commands (pre-bash). So the difficult initial set-up commands, which create environment variables that can be passed down to child processes, are put in
The transient settings and aliases which are not inherited are put in
that they can be re-read by every subshell."
英文资料:http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html
《bash guide for beginners》
https://www.gnu.org/software/bash/manual/bash.html 《gun bash manual》
http://unix.stackexchange.com/questions/119627/why-are-interactive-shells-on-osx-login-shells-by-default http://www.thegeekstuff.com/2008/10/execution-sequence-for-bash_profile-bashrc-bash_login-profile-and-bash_logout/
查出系统支持的所有shell:$cat /etc/shells
系统默认shell:echo $0 或者 ps -p $$
用户级环境变量:
临时切换shell(子shell): 目标shell名
退回父shell:exit
查看嵌套层级,也既子shell数量:
echo
"$SHLVL"
想要把当前系统shell从bash永久换成zsh?试试这个:
通过chsh命令永久变更系统shell
环境变量给谁用?什么是环境?
谁来管理环境?
环境给谁用?
什么时候用?
怎么用?
如何设置环境变量?
如何让环境变量生效?
source 或者 . 配置文件
如何清除环境变量?
如何查看环境变量?
env
下面是bash shell里一些常见变量的列表:
。。。。
改动影响较大的变量:
显示环境变量的值
printenv env_nameecho $env_name
printf
"%s\n"
"$HOME"
bashrc与profile的区别
要搞清bashrc与profile的区别,首先要弄明白什么是交互式shell和非交互式shell,什么是login shell 和non-login shell。
交互式模式就是shell等待你的输入,并且执行你提交的命令。这种模式被称作交互式是因为shell与用户进行交互。这种模式也是大多数用户非常熟悉的:登录、执行一些命令、签退。当你签退后,shell也终止了。 shell也可以运行在另外一种模式:非交互式模式。在这种模式下,shell不与你进行交互,而是读取存放在文件中的命令,并且执行它们。当它读到文件的结尾,shell也就终止了。
bashrc与profile都用于保存用户的环境信息,bashrc用于交互式non-loginshell,而profile用于交互式login shell。系统中存在许多bashrc和profile文件,下面逐一介绍:
/etc/pro此文件为系统的每个用户设置环境信息,当第一个用户登录时,该文件被执行.
并从/etc/profile.d目录的配置文件中搜集shell的设置.
/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取。有些linux版本中的/etc目录下已经没有了bashrc文件。
~/. pro每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该
文件仅仅执行一次!默认情况下,它设置一些环境变量,然后执行用户的.bashrc文件.
~/.bashrc:该文件包含专用于某个用户的bash shell的bash信息,当该用户登录时以及每次打开新的shell时,该文件被读取.
另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是"父子"关系.
某网友总结如下:
/etc/profile,/etc/bashrc 是系统全局环境变量设定
~/.profile,~/.bashrc用户家目录下的私有环境变量设定
当登入系统时候获得一个shell进程时,其读取环境设定档有三步
1首先读入的是全局环境变量设定档/etc/profile,然后根据其内容读取额外的设定的文档,如
/etc/profile.d和/etc/inputrc
2然后根据不同使用者帐号,去其家目录读取~/.bash_profile,如果这读取不了就读取~/.bash_login,这个也读取不了才会读取
~/.profile,这三个文档设定基本上是一样的,读取有优先关系
3然后在根据用户帐号读取~/.bashrc
至于~/.profile与~/.bashrc的不区别
都具有个性化定制功能
~/.profile可以设定本用户专有的路径,环境变量,等,它只能登入的时候执行一次
~/.bashrc也是某用户专有设定文档,可以设定路径,命令别名,每次shell script的执行都会使用它一次
一、Linux的变量种类
按变量的生存周期来划分,Linux变量可分为两类:
1、永久的:需要修改配置文件,变量永久生效。
2、临时的:使用export命令声明即可,变量在关闭shell时失效。
http://www.cnblogs.com/Neddy/archive/2011/03/01/1968018.html
命令补齐:http://blog.163.com/card_2005/blog/static/1178103682009104103811868/
参考文档:http://blog.csdn.net/flowingflying/article/details/5014914
http://www.blogjava.net/jasmine214--love/archive/2010/11/26/339108.html http://blog.csdn.net/aaaaatiger/article/details/1713611 运算符
"Why is
.bashrca
separate file from
.bash_profile,
then? This is done for mostly historical reasons, when machines were extremely slow compared to today's workstations. Processing the commands in
.profileor
.bash_profilecould
take quite a long time, especially on a machine where a lot of the work had to be done by external commands (pre-bash). So the difficult initial set-up commands, which create environment variables that can be passed down to child processes, are put in
.bash_profile.
The transient settings and aliases which are not inherited are put in
.bashrcso
that they can be re-read by every subshell."
英文资料:http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html
《bash guide for beginners》
https://www.gnu.org/software/bash/manual/bash.html 《gun bash manual》
http://unix.stackexchange.com/questions/119627/why-are-interactive-shells-on-osx-login-shells-by-default http://www.thegeekstuff.com/2008/10/execution-sequence-for-bash_profile-bashrc-bash_login-profile-and-bash_logout/
相关文章推荐
- 自学基础_linux_5_环境变量配置
- Linux基础:crontab 与 环境变量,以及应该注意的问题
- linux下的shell和环境变量,脚本编程的基础
- Linux基础(5)/环境变量与文件查找
- Linux学习日记 —— 10.4.2 Shell基础-Bash变量-环境变量
- Linux基础 -- 环境变量与文件查找
- linux用户环境变量的理解
- 1-常见Linux命令及java基础之环境变量细节
- linux 自学系列:环境变量设置
- linux系统开发 1 基础apt-get 进程 作业 环境变量 安装vsftpd vim gcc gdb Makefile
- linux脚本编写基础(环境变量、shell流程控制)
- 理解Linux环境变量及配置文件执行顺序
- Linux各环境变量的理解
- Linux中各种环境变量的理解
- (大数据工程师学习路径)第一步 Linux 基础入门----环境变量与文件查找
- Linux基础知识5——重定向、管道、环境变量等重要概念
- linux中有关环境变量的一些理解
- 关于对linux环境变量的理解
- 嵌入式成长轨迹5 【嵌入式环境及基础】【嵌入式Linux软件开发入门】【变量和运算符】
- linux超级基础系列——shell变量(本地变量和环境变量)