Shell and bash variable types

Source: Internet
Author: User

The Shell is process-oriented

(Bash for example)

Variables are process variables, process ends, and variables disappear.


Bash Variable type:

Environment variables

Local variables (local variables):

Positional variables

Special variables


Local variables: Set Varname=value

scope for the entire bash process


Local variables:

local Varname=value scope is the current code snippet


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

Export varname=VALUE

Or

Varname=value

Export VARNAME


Positional variables:

$


Special variables:

$? Save last command execution status return value

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

Status Return code: (0~255)

0: Correct execution

1-255: Various error executions, 1, 2, 127 system reserved

echo $? Look at the results


-------------------------------------------

/dev/null: Software devices, data black holes

-------------------------------------------

Undo Variable

Unset VARNAME

(The $VARNAME represents the action value, not the $ representation of the action variable)

View variables for the current shell

Set (including environment variables and local variables)


To view environment variables in the current shell:

Printenv

Env

Export

modifying variables

Ga=aaa

Modified: ga= $GA: Aa:ss separated by colons


Variable does not do arithmetic arithmetic (default is string save)

A=3

B=3

c= $A + $B

echo $C//3+3


Linux is just a no elf executable file


Script file First line

Shebang: Magic number (according to this selection shell execution)

#! /bin/bash

If the script cannot execute:

1. Permissions

2. Environment variable (can write absolute path if no environment variable is added)

3. Or use the Interpreter directly (bash) to execute bash f.sh, if you want it to execute independently, you must have execute permissions.


This article from the "90 Design Studio" blog, reproduced please contact the author!

Shell and bash 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.