2 Answers
2

The two sides of a pipe are in different processes. You can't share variables between these processes. If you want to share data, you either have to pass it through the pipe, or use alternate communication channels. If you need alternate communication channels, you're above the shell's capabilities, switch to a real programming language.

Here, passing lot_url alongside img_url in the second pipe seems like a good solution to me. I'd pass them on the same line. Assuming your URLs are properly escaped, you don't need any particular quoting, you can pass them on the same line. This would have the advantage of allowing a variable number of img_urls in each lot_url.

A single while loop would do here, I think. I think it would make no difference, really, since you're calling executables every iteration anyway. In this way you can share the global variable you had hoped for. Like:

source_cmd |
while read var
do fn1 "$var" |
fn2 "$var"
done

But I think better still would be to change the workflow a little - the function is nothing more than a set of shell commands based around an array. Now you're not using the array for any of them, so it should really serve to point out a common purpose for a set of commands - and the most common that I can see seems to be curl ... | sed ... . So I suggest you should make that a function that can accept parameters. So the result might look like this:

You've already accepted Gilles's answer to this question - apparently years ago, which I didn't realize - but here's another that demonstrates similar methodology to mine, and which I think would be better suited to this purpose.