Linux Command ' s Array

Source: Internet
Author: User

#数组的声明与遍历
Animals= ("A Dog" "A Cat" "A Fish")
#wrong ways
For i in ${animals[*]}; do echo $i; Done
For i in ${animals[@]}; do echo $i; Done
For i in "${animals[*]}"; do echo $i; Done

#this is what we want correct
For i in "${animals[@]}"; do echo $i; Done

#数组元素的排序
A= (F e d c b a)
echo "Original array: ${a[@]}"
A_sorted= ($ (For I in "${a[@]}"; does echo $i; done | sort))
echo "Sorted array: ${a_sorted[@]}"

#删除数组长或数组的某个元素
Foo= (a b c D E F)
Echo ${foo[@]}
Unset Foo[2]
Echo ${foo[@]}

The cut command cuts bytes, characters, and fields from each line of the file and writes those bytes, characters, and fields to standard output.
Main parameters
-B: Split in bytes. These byte locations will ignore multibyte character boundaries unless the-n flag is also specified.
-C: Split in characters.
-D: Custom delimiter, default is tab.
-F: Used with-D to specify which area to display.
-N: Cancels splitting multibyte characters. Used only with the-B flag. If the last byte of the character falls within the range of <br/> indicated by the List parameter of the-B flag, the character will be written out; otherwise, the character will be excluded.
#split string to array one demo
foo= "Hello world hello java hello docker hello spark Hello Stream"
Declare-a Bar
Read-a Bar <<< $foo

Linux Command ' s Array

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.