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.

BenMorel
  • 31,815
  • 47
  • 169
  • 296
teslasimus
  • 1,188
  • 5
  • 13
  • 22

2 Answers2

1

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

Community
  • 1
  • 1
Roman Cheplyaka
  • 36,578
  • 6
  • 70
  • 117
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

Davide Berra
  • 6,398
  • 2
  • 27
  • 47