Shell experience-usage of Variables

Source: Internet
Author: User

1. variable order

In the script, there is no global or local variable for the same process.

It is just a break. If you use a variable in a function, and there is no trace of this variable outside the function. However, as long as you have called this function, you can use this variable wherever the script goes on.

An example is as follows:

The approximate description is as follows:

1. The function is called.

#! /Bin/shtest () {A = "1" return} testecho $

Display:

Kaiwii @ Ubuntu :~ $./TST
1
2. This function is not called.

#! /Bin/shtest () {A = "1" return} # testecho $

Display:

No

Summary:

I understand this question as follows: scripts are just calling other people's programs. People do not need to create another stack to record your layers. Therefore, when writing a shell, you only need to consider the order of the variables. As for the nested (global) relationship, let's go!
2. Usage of variable $ * and $ n

For this understanding, I would like to use a knowledge about J2EE. Write the J2EE code and get the data from the request object. Then, send the data to the following layer. The response object must be used. In J2EE, variables are transmitted through the transmission between the response object and the request object. In Shell, variables of this family are similar. When you call a function or another shell file, you can add parameters later. In these functions or another shell file, you can retrieve these parameters using the $ n variable. When accessing parameters, note the order between these parameters.

3. The value must be $

You can directly use the variable name for the value assignment. To obtain the value of this variable (A), you need to use $.

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.