You just have an extra newline:
#In main.sh
a=1 ./sub.sh
This is really the same answer as 1_CR, but demonstrates the technique of passing a value to the environment of sub.sh
instead of modifying the current environment for sub.sh
to inherit.
Since this is a per-process modification of the environment, you can repeat as necessary.
a=1 ./sub.sh &
a=3 b=9 ./sub.sh &
Each instance of sub.sh
sees a different value for a
, and the second instance sees a value for b
as well.