Shell Custom Array element delimiter

Source: Internet
Author: User

Company personnel named image used to add a space, today there is a need, to bulk download this write pictures, this egg hurt

The correct URL is this

Http://url 2119 01.jpg

Http://url 001.jpg

Written into the text will be added to escape, become

Http://url\ 2119\ 01.jpg

Http://url\ 001.jpg

The result of the loop is that the egg hurts.

#!/bin/bashpic=$ (cat list.txt) for I in $picdo Echo ' $i ' done

Results

[Email protected] ~]# sh download.sh http://url211901.jpghttp://url001.jpg

It's all messed up.

Workaround:

Because of the segmentation of the array elements, it is controlled by the IFS system built-in field delimiter, so the script is rewritten as follows

#!/bin/bashpic=$ (cat list.txt) ifsbak= $IFS # Save the default ifsifs=$ ' \ n ' #指定分隔符for i in $picdo echo "$i" doneifs= $IFSBAK # Also Original default delimiter

The resulting output is as follows:

[Email protected] ~]# sh download.sh http://url\ 2119\ 01.jpghttp://url\ 001.jpg

There's no problem with downloading pictures in bulk at this time.

Shell Custom Array element delimiter

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.