OC: Windows 2008 R2 Enterprise

My task: I need to create an html file with a variable number of pictures. And for each picture attached link. This type:

<a href='$graph_url' > <img src='$graph_picture'> </a> 

Sheet (s) with links and sheet with paths to pictures are generated in advance.

Question: Is it possible in the shell to create tuples as in python? a pair of data that is processed as one object: ($ graph_url, $ graph_picture)

From them I could create a sheet and create the above html inserts:

 list=(u1,p1) (u2,p2) (u3,p3) 

Question 2: Is it possible to iterate through two sheets at once? Then I could, as an alternative, create two sheets and achieve the same result. "for i in list" is clearly not appropriate.

I will be grateful to any idea that will move me forward.

    1 answer 1

    for example:

     #!/bin/bash u=("u1" "u2" "u3") p=("p1" "p2" "p3") for i in $(seq 0 $((${#u[*]}-1))); do echo "<a href='${u[$i]}'>" echo " <img src='${p[$i]}'>" echo "</a>" done 

    result of execution:

     <a href='u1'> <img src='p1'> </a> <a href='u2'> <img src='p2'> </a> <a href='u3'> <img src='p3'> </a> 

    here:

    • ${#x[*]} - the number of elements in the array x
    • $(($x-1)) - subtract one from the value of the variable x
    • seq xy - getting a sequence of natural numbers x, x+1, ..., y
    • ${x[$y]} - getting element number y from array x
    • Thanks It works! Can you explain why there are two brackets in $ (($ x-1))? - Predicate
    • This is the posix arithmetic expression syntax - aleksandr barakin
    • found. "$ ((" makes the shell treat the inside as an arithmetic expression, not as a grouping character - Predicate