Linux Basic Variables Learning: Local variables, environment variables, special variables, positional variables

Source: Internet
Author: User

Shell: weakly typed programming languages

Strong: Variables must be declared beforehand and even initialized before they are used;

Weak: variable time declaration, even the type is not differentiated;

Variable assignment: Var_name=value

Bash Variable Type:

Environment Variables

Local variables (local variables)

Positional variables

Special variables

Local variables:

Set Varname=value: the scope is the entire bash process;  

Local variables:

Local Varname=value : The scope is the current code snippet;

Environment variable: scope is the current shell process and its child processes;

Export Varname=value

Varname=value

Export VARNAME

"Export"

Positional variables:

$, $, ...

Special variables:

$?: the execution status return value of the previous command;  

program execution, there may be two types of return values:

Program execution Results

Program Status return code (0-255)

0: Execute correctly

1-255 : Error execution, 1,2,127 system reservation;

Output redirection:

> Output override Redirection

>> Output Append redirect

2> error output overwrite redirect

2>> error output append redirect

&> correct error output redirection

Undo Variable:

unset VARNAME varname is the variable name

To view variables in the shell:

Set VARNAME but set can omit VARNAME is the variable name

View the Environment Variables command in the current shell as follows:

Printenv

Env

Export

Script: Command stack, according to the actual needs, combined with the command flow control mechanism to implement the source program

shebang: magic number

#!/bin/bash

# comment lines, do not execute

/dev/null: software devices, bit buckets, data black holes      

The script starts a child shell process when it executes;

scripts that are started on the command line inherit the current shell environment variable;

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

This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1863045

Linux Basic Variables Learning: Local variables, environment variables, special variables, positional variables

Related Article

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.