BASHRC of permanent environment variable under embedded Linux

Source: Internet
Author: User

BASHRC of permanent environment variable under embedded Linux

1). bashrc file

Under the Linux system Normal user directory (CD/HOME/XXX) or root user directory (Cd/root), with the command ls-al can see 4 hidden files,

Commands entered before the. Bash_history Record

. bash_logout commands to execute when you exit

. bash_profile execute when you log in to the shell

. BASHRC execute when you log in to the shell

Note the latter two differences: '. Bash_profile ' is read only once at the beginning of the session, while '. BASHRC ' is read every time a new terminal is opened.

These files are each user to the terminal features and properties settings, modified. BASHRC can change the environment variable path, alias aliases, and prompt . The details of how to modify it are described below.

In addition to modifying . BASHRC files in the user directory, you can also modify the files and directories such as "/etc/profile" , "/ETC/BASHRC" /ETC/PROFILE.D "under the file. However, modifying the configuration files in/etc path will be applied to the whole system, which is a system-level configuration, and the. BASHRC in the modified user directory is restricted to user-level settings. There is a difference between the two in the scope of application, it is recommended that if you need to modify, modify the. BASHRC in the user directory, that is, no root privileges and no impact to other users.

2) Path environment variable modification

The path variable determines to which directories the shell will look for commands or programs . If the directory of the command to be executed is in the $PATH, you do not have to enter the full path of the command, just enter the command directly. Some third-party software does not place the executable file in the standard directory of Linux. Therefore, adding these non-standard installation directories to the $PATH is a workaround. In addition, you will see how to handle general environment variables.

First, as a rule, all environment variable names are capitalized. Because Linux is case-sensitive, you should be aware of this. Of course, you can define some variables yourself, such as ' $path ', ' $pAtH ', but the shell will not ignore these variables.

The 2nd is that variable names sometimes start with ' $ ', but sometimes they are not. When setting a variable, use the name directly, without adding "$", as

Export Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/x11r6/bin:/usr/local/bin: $JAVA _home/bin: $JAVA _ Home/jre/bin: $PATH: $HOME/bin

"path=/usr/bin:/usr/local/bin:/bin" (no double quotes required)

To get the value of a variable, add ' $ ' before the variable name:
"Echo $PATH"
The current set PATH variable "/usr/bin:/usr/local/bin:/bin" is displayed.

Otherwise, the variable name will be treated as plain text:
"Echo PATH"
Show "PATH"
The 3rd to be aware of when dealing with $PATH variables is that you cannot just replace the variable, but instead add the new string to the original value. In most cases, you cannot use "path=/some/directory" because this will delete all other directories in the $PATH so that when you run the program at that terminal, you will have to give the full path. So, can only add: "path= $PATH:/some/directory", if you want to add/usr/local/arm/3.4.1/bin cross-compile command, the action is "path=$ Path:/usr/local/arm/3.4.1/bin "
The PATH is then set to the current value (represented by the $PATH) + the newly added directory.

So far, you have only set a new $PATH variable for the current terminal. If you open a new terminal and run the Echo $PATH, the old $PATH value is displayed and the new directory you just added is not visible. Because you previously defined a local environment variable (limited to the current terminal).

To define a global variable so that it takes effect in a later open terminal, you need to export the local variable (export), and you can use the "Export" command:

export path= $PATH:/some/directory

Now if you open a new terminal and enter the Echo $PATH, you can see the $path of the new settings. Please note that the command ' export ' only changes the variables in the current terminal and the terminal that is running later. Does not work for a terminal that is already running.

In order to permanently add the directory to the $PATH, simply add the line "Export" to the . BASHRC or/ETC/BASHRC file.

3) alias aliases

Generally there are a few words in the. BASHRC or/ETC/BASHRC file.

Alias rm= ' Rm-i '

Alias cp= ' Cp-i '

Alias mv= ' Mv-i '

With these words, when input "mv test.c LED.C" in the terminal is actually input "mv-i test.c led.c", so alias is an alias. You can add your own style aliases to the configuration file, such as "Alias Ll= ' Ls-l '", just enter "LL" in the terminal to achieve the "ls-l" function. You can also add other statements, as you prefer.

4) prompt

When you open a console, the first thing you see is a prompt (prompt), such as : [[email protected] ~]#

By default, the prompt displays the user name, host name (default is ' localhost '), current directory (in Unix, ' ~ ' for your home directory).

Traditionally, the last character can identify a normal user ($) or ' root ' (#).

You can set a prompt by $PS 1 variables.

The command "Echo $PS 1" will display the current settings. The meaning of the available characters is described in the ' prompting ' section of Man Bash.

How can I complete the ideal setup? For the forgetful beginner, the default setting is somewhat unfriendly, because the prompt displays only the last part of the current directory. If you see a prompt like this

[Email protected] bin]$
The current directory may be '/bin ', '/usr/bin ', '/usr/local/bin ' and '/usr/x11r6/bin '. Of course, you can use

PWD (output current directory, print working directory)

Can you ask the shell to automatically tell you the current directory?

Of course. Here I will mention the settings, including the prompt, mostly contained in the file '/ETC/BASHRC '. You can change the settings by editing the '. Bash_profile ' and '. BASHRC ' in the respective home directory.

In the ' prompting ' section of Man bash, these parameters (parameter) are described in detail. You can add some gadgets, such as the current time in different formats, the history number of the command, or even a different color.

A more appropriate setting:
ps1= "[\u: \w]\\$"
In this way, the prompt becomes:
[WSF:/usr/bin]$
You can test different settings by command export (for example, export ps1= "\u: \w\\$"). If a suitable prompt is found, place the settings in your '. BASHRC '. This will take effect each time the console or Terminal window is opened.

Embedded Linux Permanent active environment variable 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.