是否可以使用bash访问for循环中的多个数组

Men*_*hem 2 arrays bash for-loop

我正在尝试编写一个bash脚本,让我可以使用curl下载多个网页.对于每个网页,我希望能够传递curl页面和referer链接.我希望能够一次提供多个网页.

换句话说,我希望能够遍历我提供脚本的网页,并且对于每个页面,将关联的网页和引用链接传递给curl.

我以为我会使用数组将网页和referer链接存储在一个变量中,以为我可以在运行curl时提取数组的各个元素.

我的问题是我无法弄清楚如何让多个数组在for循环中正常工作.这是我想要做的事情的想法.此代码不起作用,因为"$ i"(在for循环中)不会成为数组.

#every array has the information for a separate webpage
array=( "webpage" "referer" )
array2=( "another webpage" "another referer" )

for i in "${array[@]}" "${array2[@]}" #line up multiple web pages
do
    #use curl to download the page, giving the referer ("-e")
    curl -O -e "${i[1]}" "${i[0]}"
done
Run Code Online (Sandbox Code Playgroud)

如果我只使用一个数组,我可以轻松地这样做:

array=( "webpage" "referer" )
REFERER="${array[1]}"
PAGE="${array[0]}"
#use curl to download the page, giving the referer ("-e")
curl -O -e "$REFERER" "$LINK"
Run Code Online (Sandbox Code Playgroud)

曾经有一个我想要一次处理的网页,我无法弄清楚如何正确地处理它.

如果有另一种方法来处理多个网页,而不必使用数组和for循环,请告诉我.

Phi*_*ipp 5

如果有另一种方法来处理多个网页,而不必使用数组和for循环,请告诉我.

使用数组很好,至少它比使用空格分隔列表或类似的黑客要好得多.只需循环索引:

array=('webpage' 'another webpage')
array2=('referrer' 'another referrer')
# note the different layout!
for i in "${!array[@]}"
do 
    webpage="${array[$i]}"
    referrer="${array2[$i]}"
done
Run Code Online (Sandbox Code Playgroud)