Shell programming Basics

Source: Internet
Author: User

This article mainly summarizes some of the basic knowledge worth noting in shell programming.

1 .#! /Bin/Bash must be placed in the first line of the file

2. num = 2. When values are assigned, spaces are not allowed on both sides.

3. Echo "this is $ {num} Nd", the role of parentheses

4. Shell default value assignment is string value assignment. Eg Var = 100 Var = $ var + 100 echo $ var result: 100 + 100

5. Integer Operation

Var = 100.

(1) Let "Var + = 1"; let indicates mathematical operations

(2) Var = $ [Var + = 1]; $ [] perform mathematical operations on the expressions in parentheses before outputting them.

(3) Var = 'expr $ var + 1'; expr is used for integer calculation. Pay attention to the spaces on both sides of the plus sign. ', not single quotation marks', indicates executing the shell command in.

6. The shell comparison operator also uses = instead of =. At this time, the = operator can have spaces or no space on both sides.

7. Shift command

You can also add a parameter to delete a parameter from the beginning.

The content of EG test. Sh is as follows:

#! /Bin/bash

Echo $1 $ #

Shift 2

Echo $1 $ #

Run./test. Sh 1 2 3 4

Result: 1 4

3 2

8. In shell, the function is called by function name without brackets.

When passing parameters to a function, you can directly follow the function name.

Eg

Show ()

{

Echo $1

}

Show VaR

9. Shell debugging

Sh-x yourscript executes the script and displays the values of all variables

Sh-N yourscript: This command returns all syntax errors.

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.