Environment variables under bash

Source: Internet
Author: User

Tag: blank target Context string

The definition of a variable: simply by letting a particular string represent something that is not fixed.

Categories of variables:

Environment variables: scoped to the current shell process and its child processes

Local variables: scoped to the current shell process

Local variables: scoped only to a snippet of code in the current shell process (usually a function context)

Positional variables:

Special variables:

Access to variables: Echo

As shown, the variable is used just by using echo and then adding a $ to the variable name.

Setting and modifying variables: variables = variable contents

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/D0/wKiom1XtkpjTFVIaAACRJGv92uk130.jpg "/>

Setting rules for variables:

    1. Variable and variable contents are connected by an equal sign
    2. Cannot directly connect whitespace on both sides of equal sign
    3. Variable names can only be English letters and numbers, but cannot begin with numbers
    4. Variable contents If there is a space, you can use double quotation marks or single quotation marks to cause the contents of the variable

      Double quotation marks are weak references, such as special characters in double quotation marks can keep their original particularity

      Single quotes are strong references, where special characters are only ordinary characters

    5. You can escape a special word to a generic character by escaping the backslash \ Character
    6. In a sequence of instructions, you can use the inverted single quotation mark ["] or [$ ()] to refer to other directives.
    7. You can append content with variable = "$ variable name" or variable =$ (variable)
    8. To execute in Bash's subroutine, you need to use export to define the environment variable
    9. To cancel the use of a variable unset variable name

View of variables (evn,export,set)

EVN: View environment variables and descriptions

Export: Same as EVN, but can also customize variables as environment variables

Set: You can view not only the environment variables but also the custom variables

Common environment variables:

Home: Represents the user's home directory

Shell: The shell used by the representative

Histsize: How many records can be stored on behalf of

Mail: Represents the path where the mailbox is stored

Path: Represents the storage path of the execution file

LANG: The language used by the representative

Random: Take the stochastic number (0-32767)

$: PID representing the current shell

?: Feedback on success of last instruction execution

0: Success for execution

1-255: failed for execution

PS1: Command Prompt settings

\d: Date format showing "Day of the Week"

\h: Full host name

\h: Takes the first name of the hostname before the decimal point

\ t: Time displayed as 24-hour format [HH:MM:SS]

\ t: Time displayed as 12-hour format [HH:MM:SS]

\a: Show time in 24-hour format [hh:mm]

\@: Show time in 12-hour format [hh:mm]

\u: Displays the account name currently in use

\V: Show version information for bash

\w: Displays the full working directory name

\w: Displays the base name of the working directory

\#: Shows the release of the first few instructions

\$: Display prompt

Bash Environment configuration:

Global configuration:

/etc/profile

/etc/profile.d/*.sh

/etc/bashrc

Personal configuration:

~/.bash_profile

~/.bashrc

Environment variables under bash

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.