Shell variables and variable types

Source: Internet
Author: User


650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/99/D8/wKioL1lNDBWiKp5qAAHumaoOG3U812.png-wh_500x0-wm_ 3-wmp_4-s_3170601832.png "title=" variable. png "style=" float:left; "alt=" Wkiol1lndbwikp5qaahumaoog3u812.png-wh_50 "/>












The shell is a weak type into a language


variable assignment : var_name=value

undo Variable : unset var_name


Bash:

variable type 1, environment variable

Export Var_name=value

The script starts a child shell process when it executes:

Scripts that are started on the command line inherit the environment variables of the current shell

Program scripts that are automatically executed by the system (not command-line startup) require self-defined environment variables

2. Local variables (local variables)

Var_name=value acts on the entire bash process.

The local Var_name=value acts on the current code snippet.

3. Position variable

$1,$2,.....

4. Special variables

$?: Save Last Command execution status return value

There may be two return values after program execution

1. Program execution Results

2. Program Execution status return code (0-255)

0 is performed correctly

1-255: Error execution 1,2,127 system retention


How does bash achieve conditional judgment?

condition test Type :

1. Integer test

2. Character test

3. File test

Expressions for conditional tests :

[expression] Two spaces or grammatical error

[[expression]] Ibid.

Tset expression

integer comparison :

-EQ: Tests whether two integers are equal such as $A-eq $B

-NQ: Test whether two integers are unequal to true

-GT: Test whether a number is greater than another number

-LT: Tests whether one number is less than the other

-ge: greater than or equal to

-le: Less than or equal to

logical relationship of the command :

Logic and:&&

Logical OR: | |

#!/bin/bash!  ID user1 &>/dev/null && useradd user1 && echo "user1" |passwd--stdin user1 &>/dev/null | | echo "User already exists"

Conditional judgment, control structure

if judgment condition; then

Statement1

Statement1

.....

Else

Statement3

Statement4

....

Fi

This article is from the "12759777" blog, please be sure to keep this source http://12769777.blog.51cto.com/12759777/1941542

Shell variables and variable types

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.