I can't get this of my head, just remembers that linux use two variables settings.
First you have the shell variables, which is not transferred between parent to child.
And you have something called environment variables. that stays between parent to child.
So if you want the variable to stay between parent to child you need to export it.
If i don't misunderstand your problem it seems to maybe be that the shell spawn's another shell and don't inherit the variable between parent to child.
So maybe when you assign your variable within your shell, just add the command export in front of it like this:
export N="Test"
not like this:
N="Test"
Lets play with this like this.
> TEST="Test"
> echo $TEST
Test
> bash
> echo $TEST
> exit
exit
> echo $TEST
Test
> export TEST
> bash
> echo $TEST
Test
> exit
exit
> export TEST1="Test2"
> bash
> echo $TEST1
Test2
> exit
exit