I have a text file with variables in format VARIABLE=value like:
PID=123123
WID=569569
TOKEN=456456456
Where VARIABLE has only uppercase letters and value contains only alphanumeric characters ([a-zA-Z0-9])
Now I want to pass these variables to a script as named arguments (options):
./script.sh --PID 123123 --WID 569569 --TOKEN 456456456
Is there a simple way to do this in bash?
I have read:
- How to pass command line parameters from a file - this question is about position arguments and named arguments
- Set environment variables from file of key/value pairs - this question is about environment variables
xargshas problematic corner cases when the input file is large, but if it's just a few options,sed 's/^/--/;s/=/ /' file | xargs ./script.shbashvariable definition, so if you would say that the text file's content simply is a piece of bash code, you could simply source the file usingsource FILENAME. This comes with all risks and perils of such an approach, i.e. as long as you are the one who prepares the "text file", you are safe, but if the file comes from a place outside of your control, you better do some parsing.