System variables are written in the difference between. Bash_profile and. BASHRC

Source: Internet
Author: User

Configure a proxy today, serious I have been blindfolded, not the export http_porxy=xxx.xxx.xxx.xxx:xxxx

Then restart the service network restart, still can't connect the outside network!

Premise: I was connected via SSH to the past

1> when I write the environment variable to. BASHRC, restart the service, do not take effect

2> when I write the environment variable to. Bash_profile, restart the service, take effect

3> when I write the environment variable to. Bashrc,if before the judgment.

Such as:

#. Bashrcexport http_proxy=192.168.57.156:3128Export Https_proxy=192.168.57.156:3128Export Ftp_proxy=192.168.57.156:3128# User specific aliases and FunctionsaliasRM='rm-i'aliasCP='cp-i'aliasMV='mv-i'# Source Global Definitionsif[-F/ETC/BASHRC]; Then        . /etc/BASHRCfi

This time is in effect.

For a I have a special research spirit of me, I must understand ah, find the information as follows (key place I marked red):

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

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

According to the Bash man page, was .bash_profile executed for login shells, while was .bashrc executed for interactive non-login Shel Ls.

What is a login or Non-login shell?

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

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

Why different files?

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

You have want to see it on login and so are only want to place the this in your .bash_profile .

The gist of the above is that it is necessary to print the diagnostic information of each login machine. bash_profile

If you put it on your, you'll see .bashrc it every time you open a new terminal window.

But if you need to see each time you open a new terminal window, you need to. 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 NE W terminal window, calling .bash_profile instead of .bashrc . The other GUI terminal emulators is the same, but most tend not.

Recommendation

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


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

If [-f ~/.BASHRC]; Then   source ~/.BASHRCFI

Now if you are login to your machine from a console would be .bashrc called.

Through the above analysis we know that I am connected via ssh, is the login user, so my variable to take effect, need to put in the. BASHRC inside

System variables are written in the difference between. Bash_profile and. BASHRC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.