Shell Programming Overview and variables

Source: Internet
Author: User

Dynamic language: Interpreted language, is a weak type of language, Characteristics: Edge interpretation edge execution. Example: PHP, SHELL, Python, Perl

Weak: variable time declaration, or even type-insensitive.

Strong: Variables must be declared beforehand and even initialized before they can be used.

BASH: itself is a software, script interpreter.

Shell scripts are process-oriented.

Bash Variable type:

Environment variables

Local variables (local variables)

Positional variables

Special variables

Local variables:

Varname=value; scope: The entire bash process

Local variables

Local varname=value; scope: For the current code snippet

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

①export Varname=value

②varname=value

Export VARNAME

Positional variables:

$1,$2,...

Special variables:

$7: 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 codes (0-255)

0: Correct execution

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

echo $? View the status of the previous command execution

Reference variable: $ (VARNAME), parentheses can sometimes be omitted

When the script executes, it starts a child shell process, and the script that is started on the command line inherits the current shell environment variable, and the system automatically executes the script (not the command line startup) that requires a self-defined environment variable

Output redirection:

> Overwrite redirects

>> Chasing heavier orientation

2> Error Redirection

2>> Error Append redirect

&> simultaneous redirection

Undo Variable: unset VARNAME undo environment variable, local variable

View variables in the current shell: including environment variables, local variables

Set

To view environment variables in the current shell:

Printenv

Env

Export

Add something new to a variable:

Name=xiao

Name= $NAME:/liu after filling

Name=tian: $NAME Pre-fill

Note: All shell variables are strings and cannot be used for arithmetic operations

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

First script:

The first line must be written at the beginning of the script:

#! /bin/bash

#注释行, do not perform

The script written in general does not have permission to execute: chmod +x filename

However, there are two ways of doing this:

① the path name of the file under path path

The ② is executed only under the current path./filename

Remove execution permissions: chmod-x filename

Specify bash interpreter to execute bash filename

Shell Programming Overview and 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.