Six. Bash script (bash scripts), bash variable

Source: Internet
Author: User

Shell variables, shell scripts basics

Shell variable Categories: environment variables, local variables, local variables, positional variables, special variables

1.shell Local Variables

(1) Assigning values to variables

Name= "Value"

Value

String Name= "string"

Variable reference name= "$name"

Command Reference name= ' command ', name=$

(2) Variable reference

$name,%{name}

"": if referenced, the variable reference is replaced with the value of the variable
': Strong reference, where the variable reference is not replaced with its variable value, keeping the original string
' Command ', $ (command): Commands reference

(3) Delete local variables

unset name

(4) Read-only variable, can not change its value after setting, can not be destroyed, only after the shell process ends its life

ReadOnly Name

Declare-r Name

2.shell Environment variables

(1) Assigning values to variables

Export Name=value

Declare-x Name=value

Local variable promoted to environment variable Expoert name, declaere-x name

(2) Display environment variables

Export

Env

Printenv

3. Deleting variables

unset name

4. Show all variables

Set:set or unset values of the shell options and positional parameters.

5. Position variables

Calling parameters passed to the script from the command line in the script

$, $ ... : corresponding to the command line of the 1th, 2nd ... A parameter

$: Command itself

$*: All parameters passed to the script, all parameters as a whole

[Email protected]: All parameters passed to the script, each parameter is independent

$#: Number of arguments passed in a script

Shift [n]: Kicks out n parameters

6. Logic operation:

&&: With

|| : OR

! : Non-

Short-circuit Operation:

A&&b: If A is false, B is not executed

a| | B: If True, the B is not executed

7. Shell programming Features: Process oriented (sequential execution, loop execution, select execution), interpreting execution

8. The first line of the script indicates the interpreter used to execute the script

#!/bin/bash
#!/usr/bin/python
#!/usr/bin/perl

9. Pstree:display a tree of process: show the tree of processes

Six. Bash script (bash scripts), bash variable

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.