0

I'm building a sitemap from mysql and to speed things-up I would like to send my function to the background. When I do so, the "$SITEMAP" variable appears empty.

what I've tried is setting export SITEMAP="$SITEMAP"

for ((i=0; i<CNT; i++)); do
    xml() {
        ...
        export SITEMAP="$SITEMAP"
    }
    xml &
    echo -e "$SITEMAP"
done

ps: without sending to background the "xml" function, script works correctly.

4

2 回答 2

1

Because the background shell is a different process. The rest is explained e.g. here.

于 2013-03-05T16:16:09.357 回答
1

When you call

 xml &

you start a different process, then the export is valid only in the environement of the latter.

Remove the & and it will work

于 2013-03-05T16:17:54.950 回答