I want to make variable foo defined in a.sh usable in b.sh, and then call b.sh on a.sh.
Environment: Ubuntu 16.04.5 LTS

Applicable source code


foo = aaa
#Process to make some variable foo usable by b.sh
MSG = `./B.sh`
echo ${MSG}


echo ${foo}

https://orebibou.com/2014/11/%E3%82%B7%E3%82%A7%E3%83%AB%E3%82%B9%E3%82%AF%E3%83% AA% E3% 83% 97% E3% 83% 88% E3% 81% A7% E5% A4% 96% E9% 83% A8% E3% 83% 95% E3% 82% A1% E3% 82% A4% E3% 83% AB% E3% 81% AB% E8% A8% 98% E8% BF% B0% E3% 81% 95% E3% 82% 8C% E3% 81% 9F% E5% A4% 89/
In the middle of the above, I tried "2. When describing the variables defined in the script file as text in the external file (configuration file)".
The information on this site is a text file, but this time I want to operate and execute an external script file.
Also, in the example of the site, the file is read line by line. Isn't it possible to read the file at once and apply only the value of the variable?

Question summary

1, How can I store values ​​in the variables from a.sh to b.sh and run b.sh on a.sh?
2. If I want to manipulate an external file with a shell script, is there any way other than reading line by line?