One of the Bash shell basics

Source: Internet
Author: User
Tags variable scope

Bash Variable type:

Environment variables

Local variables (local variables)

Positional variables

Special variables


Local variable: Valid only in the current process (shell).

BASH: Direct use, no need to declare: Name = Jerry;

Variable substitution: How to reference a variable: ${variable}. Curly braces can be omitted most of the time, as in the above example, to use the values in a variable, echo$name.

Exception: double quotation marks (if referenced): for example, Name = pig, want to output there is some pigs need to write:

echo "There is some ${pig}s"

Single quotation mark (strong reference): in single quotes, even using ${pig},bash still does not use the data in the variable, but directly output ${pig}, the variable as a string.

Local variable scope: Entire bash process


Local variables: Local, valid only for the current code snippet


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

Export Varname=value

Positional variables: $1,$2, referencing script parameters

Special variables:

General program execution has two types of return values: execution result and execution state

$?: Saves the execution status return value of the previous command. Success for: 0, others for failure

Status: 1, 2,127: Command error. System reservation.


Output redirection:

> Overwrite redirects

>> Chasing heavier orientation

2> Error Overwrite redirect

2>> Error Append redirect

&> simultaneous redirection

Output redirection has a special location in the/dev/null: bit bucket. The data black hole can output any information inside.

ID student &>/dev/null The result of the command, regardless of the result of the failure or success, to the output here.


Undo variable: unset variable name

View variables: Set without any parameters

View current Environment variables: env or export




This article is from the Linux learning blog, so be sure to keep this source http://884482.blog.51cto.com/874482/1695821

One of the Bash shell basics

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.