Linux-bash Environment variables

Source: Internet
Author: User

Remark: Blog Summary draw lessons from the Horse brother class notes

Date: 2015.09.07

Linux_bash Environment variables

Bash explained

Bash can be a command language interpreter

/etc/profile.d/*.sh
~/.bash_profile
Function:
(1) Define environment variables, such as path, PS1
(2) run a command or script
BASHRC class: Provides configuration for non-interactive logon shell
/etc/bashrc
~/.bashrc

Function:
(1) Define command aliases;
(2) define local variables;

Variables: Memory space, variable name, changeable amount

Type:
Environment variables: scope current shell process and its child processes

Local variable: scope current shell process

Local variables: scoped only to a snippet of code in the current shell process (usually a function context)
Position variable: $ $, $
Special variables: $?
How variables are defined:
Bash built-in variables: can be called directly, built in a number of environment variables, such as Path
Custom variables:
Variable assignment: variable name = value
Bash Weak type:
When a variable stores data, it is written by default, and any variable can be directly referenced without being declared;
120:24bits
120:8bits
To define a local variable:

Defining Variables Name=value

Go to the next bash bash

View: Set

For details, see:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/D1/wKiom1XtpzXDY3XsAACuV2uyeVo523.jpg "title=" 1.png " alt= "Wkiom1xtpzxdy3xsaacuv2uyevo523.jpg"/>

Define Environment variables:
Define environment variables export name=value or use Declare-x name=value

See how many of the environment variables are used: env, printenv, export

See:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/D1/wKiom1Xtp-GDPpRrAADV-4ULI4g851.jpg "title=" 2.png " alt= "Wkiom1xtp-gdpprraadv-4uli4g851.jpg"/>

Undo Variable:
unset name

See:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/CE/wKioL1Xtqo6CfUmoAAEm__8xsb4873.jpg "style=" float: none; "title=" 3.png "alt=" Wkiol1xtqo6cfumoaaem__8xsb4873.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/CE/wKioL1Xtqo6z6KQPAABxS6vVO-o980.jpg "style=" float: none; "title=" 4.png "alt=" Wkiol1xtqo6z6kqpaabxs6vvo-o980.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/CE/wKioL1Xtqx3SUemxAACJ8PNypw4755.jpg "title=" 5.png " alt= "Wkiol1xtqx3suemxaacj8pnypw4755.jpg"/>

Reference variable:
${name}, $name

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/CE/wKioL1Xtq3Sz6E93AACD80zrl_c027.jpg "title=" 6.png " alt= "Wkiol1xtq3sz6e93aacd80zrl_c027.jpg"/>

Reference symbols in bash:
': Strong reference, variable substitution does not occur

"": weak reference, variable substitution will occur

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/CE/wKioL1Xtr0WB9VRjAACnaT9Xwq8891.jpg "title=" 8.png " alt= "Wkiol1xtr0wb9vrjaacnat9xwq8891.jpg"/>

": Command Reference

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/CE/wKioL1XtrG3gpHnFAAB8ACPWEAo975.jpg "title=" 7.png " alt= "Wkiol1xtrg3gphnfaab8acpweao975.jpg"/>

Shell Logon Type:
Interactive login:
Login directly through the terminal;
User Switching implemented by su-l username command;
Non-interactive logon:
A command-line window opens under the graphical interface;
Execute the script;
Su Username;
Configuration file Action Order:
Interactive login:
/etc/profile--/etc/profile.d/*.sh--and ~/.bash_profile--~/.BASHRC--/ETC/BASHRC

Non-interactive logon:
~/.BASHRC--/ETC/BASHRC-/etc/profile.d/*.sh

The more the sequence

How does the new configuration of the Edit profile definition take effect?
(1) Re-login;
(2) Let the current shell process to re-read the specified configuration file;
Source/path/to/somefile
. /path/to/somefile
Note: Side effects

Problem:

1. Define aliases that are valid for all users?

Vim/etc/bashrc

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/D2/wKiom1XtsnzSkQQFAACbGmQSoj4159.jpg "style=" float: none; "title=" 9.png "alt=" Wkiom1xtsnzskqqfaacbgmqsoj4159.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/CF/wKioL1XttKbAvoJbAADKVLN2FiI366.jpg "style=" float: none; "title=" 10.png "alt=" Wkiol1xttkbavojbaadkvln2fii366.jpg "/>

2. What if only the modification of the PATH environment variable takes effect for the root user?

Vim ~/.bash_profile

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/D2/wKiom1XttCDxBc1gAABWKEve9kM205.jpg "style=" float: none; "title=" 12.png "alt=" Wkiom1xttcdxbc1gaabwkeve9km205.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/CF/wKioL1XttkrCy3f-AABSi-iOk-A073.jpg "style=" float: none; "title=" 11.png "alt=" Wkiol1xttkrcy3f-aabsi-iok-a073.jpg "/>

Okay, here we are.


This article is from the "It-style" blog, make sure to keep this source http://huichengu.blog.51cto.com/2495968/1692566

Linux-bash Environment variables

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.