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
  • 34,448
  • 50
  • 182
  • 322
teslasimus
  • 1,238
  • 5
  • 15
  • 23

2 Answers2

1

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

Community
  • 1
  • 1
Roman Cheplyaka
  • 37,738
  • 7
  • 72
  • 121
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,387
  • 2
  • 29
  • 50