Let us say I have a txt file vars.txt
like this.
VAR1=32
VAR2=47
VAR3=78
Now if I simply do source vars.txt
, these variables won't be exported as environment variables because I didn't prefix them with export
.
So, my question is, is there a way to export all those variables without having to prefix them with export in the file?
Yes, there is a way: set -a
From help set
Options:
-a Mark variables which are modified or created for export.
To export every variable in your file you would do
set -a
source yourFile
set +a
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.