The Linux system details the variables in Linux bash

Source: Internet
Author: User

(Big podium: the first in-country it online education hybrid adaptive Learning)

The variables are familiar, but what are the types of these variables, and what are the differences in the use of the specific usage? This article is organized to share to you:

First, Bash Variable Type:

Local variables

Local variables

Environment variables

Positional variables

Special variables (built-in)

second, local variables:

Varname=value: Scopes are available for the entire bash process;

Variable Naming conventions:

1. Can only contain letters, numbers and underscores, and start with letters and underscores

2. It is best not to duplicate the system's existing environment variables

3. See the meaning of the name

third, local variables:

Local Varname=value: Scope is the current code snippet;

iv. Environment variables:

The scope is the current shell process and its child processes and cannot affect its parent process;

Export Varname=value, if the variable is already defined, it can only be exported varname with the variable name, i.e.

1. Export Varname=value

2. Varname=value

Export VarName

The script launches a child shell environment variable when the command is executed:

Scripts that are automatically executed by the system (not command-line startup) require a self-defined environment variable;

Five, Position variable:

$1,$2,$3, ...

Cat first.sh Test.txt Hello

$1:first.sh

$2:test.txt

$3:hello

Shift: kicks off parameters

Shift N: kicks off n parameters and kicks off a parameter by default

vi.. Special variables:

$?: The return value of the previous command execution state:

There are two possible types of return values for program execution:

1. Program execution Results

2. Does the program state return (0-255)

0 to perform the correct

1-255 Execution Error (1,2,127 system reservation);

$#: Gets the total number of parameters in the current shell command line

$*: Gets all the parameters of the current Shell "$ ..., under IFS control

[Email protected]: All parameters of this program "$1″" $2″ "$3″" ... ", not controlled by IFS

$ A Gets the file name of the currently executing shell script

$n gets the nth parameter value of the currently executing shell script, n=1..9

$$ gets the current shell's process number (PID)

$! PID that executes the previous instruction

The Linux system details the variables in Linux 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.