Why use xargs
? When you can just source
the file in the current shell
You can use the set
builtin, along with the export
instead of using a non-shell built-in like xargs
. Just do below
set -o allexport
. ./file_containing_variables
set +o allexport
The usage of allexport
flag with you set(-o)/unset(+o) allows you to export variables directly from the command-line. The second line is the POSIX
source
(dot followed by variable name) command to reflect all variables to the current shell and within the allexport
flag, it is made available permanently.
Refer GNU set
built-in page for more details.
Another way in bash
using input re-direction on the file
while IFS= read -r line; do
export "$line"
done <file_containing_variables