Linux Commands - source (export variable)

by
Jeremy Canfield |
Updated: July 19 2024
| Linux Commands articles
The source command can be used to:
- make variables set in some other script available in your shell
- make lists/arrays set in some other script available in your shell
- make functions set in some other script available in your shell
Let's consider a BASH shell script named example.sh that contains the following.
#!/bin/bash
my_variable="hello"
my_array=(hello world)
function my_function {
return "world"
}
Running the script and then attempting to echo $my_variable will produce no output.
~]# bash example.sh
~]# echo $my_variable
The source command can be used make the variables, lists/arrays/, and functions set in the script available in your shell.
~]# source example.sh
Or, just a single period can be used.
~]# . example.sh
Now, echo $my_variable should produce output.
~]# echo $my_variable
Hello World
Did you find this article helpful?
If so, consider buying me a coffee over at