Shell Programming Notes (II) __ Programming

Source: Internet
Author: User
Tags scalar

Array variable read-only variable delete variable environment and shell variable

I'm finally going to start writing shell scripts. Array Variables

Create an array variable by assigning values directly to the array's index:

Array[index]=value

Note: Index is a range of values [0, 1023]
If a scalar name and array name are duplicate, then the value of the scalar corresponds to the value of the array 0 index

Another way to initialize an array, you can assign a value to multiple elements at once

The way of Access is also given above
The form is like this: ${array[index]}
Use this way to access all elements in an array echo ${array[*]}

If we define an array element such as: fruit[3]= "passion Fruit"
So when we access the array using ${fruit[*]}, the shell interprets the array as 5 items, and then we need to use ${fruit[@]} to let the shell know that we want to output 4 items

I don't really see what's too big difference. read-only variable


You can set a variable to read-only by using the ReadOnly command, which is equivalent to the const keyword in a high-level language and can only be modified one time to delete a variable at initialization time

To delete a variable using the unset command, thereadonly variable cannot be deleted
environment and Shell variables

First, let's illustrate the concept of environmental variables:
when the shell runs a program, it passes a set of variables to the program called the environment. The environment is usually a small subset of all the variables defined by the shell. Every variable in the environment is called an environment variable

In addition to local variables and environment variables, there is also a variable called a shell variable
Some shell variables are environment variables, some are local variables

The output environment variable uses the command export name, which means that local variables are placed in the environment through the Export command

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.