Array of shell programming uses

Source: Internet
Author: User
Tags array length

Record the use of arrays in the shell

The main is the creation of elements, elements of the increment, delete, change operation.

1#!/bin/Bash2 3 #基本数组操作4A= (1 2 3) # # () denotes an empty array5 Echo "a No. 0 element:"${a[0]}6 Echo "all elements:"${a[@]}7 Echo "Array Length:"${#a [@]}8 Echo "----------------------------------------------"9 Ten #遍历数组 One Echo "To iterate over an array:" A  forIteminch${a[@]} -  Do -     Echo$item the  Done - Echo "----------------------------------------------" -  - # #元素操作 +A= (${a[@]}4) - Echo "after appending 1 elements to the end:"${a[@]} +a[1]=5 A Echo "after modifying a 1th element:"${a[@]} atUnset a[1] - Echo "after removing the 1th element:"${a[@]} - unset a - Echo "after deleting all elements:"${a[@]} - Echo "----------------------------------------------"

Execution Result:

No. 0 Element: 1
All elements: 1 2 3
Array Length: 3
----------------------------------------------
To iterate over an array:
1
2
3
----------------------------------------------
After appending 1 elements to the end: 1 2 3 4
After modifying the 1th element: 1 5 3 4
After removing the 1th element: 1 3 4
After deleting all elements:
----------------------------------------------

Array of shell programming uses

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.