Bash: passing environment variables
This is a wiki page. Be bold and improve it!
If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.
For environment variables to be visible from within a bash script, you must export
them.
Given the bash script:
#!/bin/bash
echo $myvar
The environment variable myvar
must be set this way:
$ myvar="test"; # This won't work.
$ export myvar="test"; # This works.
Another solution would be to source another script where those variables are defined.
You may source in a sub-shell in order to limit the scope of the variables:
( . ./all_my_variables.sh )