Shell splits strings into Arrays

Source: Internet
Author: User
#! /Bin/bash
A = "one, two, three, four"
# To split $ A, you can:
Old_ifs = "$ ifs"
Ifs = ","
Arr = ($)
Ifs = "$ old_ifs"
For s in $ {arr [@]}
Do
Echo "$ S"
Done
The above code will output
One
Two
Three
Four

Arr = ($ A) is used to split string $ A into arrays $ arr $ {arr [0] }$ {arr [1]}... respectively store the split array 1st 2... item, $ {arr [@]} stores the entire array. The variable $ ifs stores the delimiter. Here we set it to comma
"," Old_ifs is used as the default backup separator to restore the default backup after use

The command used to execute integer arithmetic operations in Bash is let;
The syntax format is: let arg ....

For example, let
J = I * 6 + 2 is equivalent to (j = I * 6 + 2 ))


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.