今天配置一个代理,正儿八经的把我搞蒙了,不就是export http_porxy=xxx.xxx.xxx.xxx:xxxx

然后重启服务service network restart ,依然连接不了外网!

前提:我是通过ssh连接过去的

1>当我把环境变量写到.bashrc,重启服务,不生效

2>当我把环境变量写到.bash_profile的时候,重启服务,生效

3>当我把环境变量写到.bashrc,if判断之前的时候

如:

# .bashrc

export http_proxy=192.168.57.156:
export https_proxy=192.168.57.156:
export ftp_proxy=192.168.57.156:
# User specific aliases and functions alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i' # Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

这个时候是 生效的。

对于一个我很有专研精神的我,肯定要弄明白呀,找了资料如下(重点地方我标记红色):

When working with Linux, Unix, and Mac OS X, I always forget which bash config file to edit when I want to set my PATH and other environmental variables for my shell. Should you edit .bash_profile or .bashrc in your home directory?

You can put configurations in either file, and you can create either if it doesn’t exist. But why two different files? What is the difference?

According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

What is a login or non-login shell?

When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.

But, if you’ve already logged into your machine and open a new terminal window (xterm) inside Gnome or KDE, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.

Why two different files?

Say, you’d like to print some lengthy diagnostic information about your machine each time you login (load average, memory usage, current users, etc).

You only want to see it on login, so you only want to place this in your .bash_profile.

上面说的大意就是说:打印每次登录机器的诊断的信息的时候需要.bash_profile

If you put it in your .bashrc, you’d see it every time you open a new terminal window.

但是如果你需要查看每次打开新的终端窗口的时候,需要.bashrc

Mac OS X — an exception

An exception to the terminal window guidelines is Mac OS X’s Terminal.app, which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. Other GUI terminal emulators may do the same, but most tend not to.

Recommendation

Most of the time you don’t want to maintain two separate config files for login and non-login shells — when you set a PATH, you want it to apply to both. You can fix this by sourcing .bashrc from your .bash_profile file, then putting PATH and common settings in .bashrc.

To do this, add the following lines to .bash_profile:

if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

Now when you login to your machine from a console .bashrc will be called.

通过上面的分析我们知道,我是通过ssh连接的,是登陆用户,所以我的变量要生效,需要放在.bashrc里面

系统变量写在.bash_profile和.bashrc的区别的更多相关文章

  1. Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别)

    在linux系统下,如果下载并安装了应用程序,在启动时很有可能在键入它的名称时出现"command not found"的提示内容.如果每次都到安装目标文件夹内,找到可执行文件来进 ...

  2. Linux下环境变量(.bash_profile和.bashrc的区别)

    在linux系统下,如果下载并安装了应用程序,在启动时很有可能在键入它的名称时出现"command not found"的提示内容.如果每次都到安装目标文件夹内,找到可执行文件来进 ...

  3. 2018/05/02 每日一学Linux 之 .bash_profile和.bashrc的区别

    最近一直在学习其他,导致博客就疏忽了,很不好(其实就是自己懒了......). -- 为什么要使用 .bash_profile和.bashrc ? 在平常的使用中,有些文件夹或者命令很长,在执行时需要 ...

  4. linux关于profile 、bashrc 、.bash_profile、.bashrc的区别

    linux关于profile .bashrc ..bash_profile..bashrc的区别 - /etc/profile /etc/bashrc ~/.bash_profile ~/.bashr ...

  5. /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 的区别(转)

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一个运 ...

  6. .bash_profile和.bashrc的区别(如何设置生效)

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一个 ...

  7. Linux——.bash_profile和.bashrc的区别(如何设置生效)

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置./etc/bashrc:为每一个运 ...

  8. .bash_profile和.bashrc的区别,ubuntu下为.profile,没有.bash_profile

    .bash_profile 开机自动加载,比如java的环境变量放在里面 .bashrc打开shell或终端就会加载该文件,比如起的别名或快捷方式放里面.alias设置就在其中. 还有一个.profi ...

  9. .bash_profile和.bashrc的区别

    参考资料: http://blog.163.com/wang_hai_fei/blog/static/309020312008728333912/

随机推荐

  1. 微软Windows 7 “可启动U盘”制作工具及使用方法,非常的简单

    目前,用“可启动U盘”替代光驱光盘安装操作系统,已经成为一种时尚(至少对没有刻录机或不愿购买光碟的群体是这样).制作“可启动U盘”的方法和工具很多,区别无非是制作的难易程度和对“U盘类型”的支持程度. ...

  2. (13)[Xamarin.Android] 不同分辨率下的图片使用概论

    原文 [Xamarin.Android] 不同分辨率下的图片使用概论 设计Android App的时候,其尺寸众多也是一个挑战之一.要针对不同尺寸设计Android App时,就要先来了一下dpi(d ...

  3. java学习之多线程

    进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础. 线程(Lightweight Process,LWP)是程序中一个单一 ...

  4. C# MVC 自学笔记—6 编辑方法和编辑视图

    ==============================翻译============================== 运行该应用程序并浏览到Movies控制器通过将/Movies追加到您的浏览 ...

  5. window.open打开新页面,并将本页数据用过url传递到打开的页面;需要两个页面;

    页面1 <!doctype html> <html lang="en"> <head> <meta charset="UTF-8 ...

  6. Android 自动编译、打包生成apk文件 3 - 使用SDK Ant方式

      相关文章列表: < Android 自动编译.打包生成apk文件 1 - 命令行方式> < Android 自动编译.打包生成apk文件 2 - 使用原生Ant方式> &l ...

  7. oracle 快照(snapshot) 管理

     ----手工创建oracle 快照 BEGIN DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT (); END; / ---删除快照 详细快照信息能够查看视图 ...

  8. codefirst初尝试

    Code First 约定 借助 CodeFirst,可通过使用 C# 或Visual Basic .NET 类来描述模型.模型的基本形状可通过约定来检测.约定是规则集,用于在使用 Code Firs ...

  9. html 中的name,id ,value,class,list 作用与区别

    name: 单独一个网页中,一个控件是否设置name不会影响这个网页功能的实现.当我们需要把这个控件 所关联的数据传递到数据库时,就必须设置name属性,否则这个值是没办法传到服务器保存的: id: ...

  10. HTML系列(六):划分文档结构

    常见的网页结构布局是酱紫的,真是美美哒^O^: 一.添加基本标题h1~h6(没什么好说的): 二.标题分组hgroup <hgroup>用来将标题和子标题进行分组.如果一篇文章articl ...