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