I would like to a code snippet that reads a properties file and defines variables in multiple other scripts, to avoid coding the same in each of my scripts.
For example, I want to be able to include the execution like below, in many scripts, after some initial work from each of the scripts, that have no relationship with each other
while IFS='=' read -r key value
do
echo "key ${key}"
if [[ ${key} =~ ^# ]]; then
echo "comment line ${key}, skipping....."
continue
fi
eval ${key}=\${value}
echo "key ${key} : value ${value}"
done < kafka-env-parameters.txt
Since the parameter file and the defined variables will be same for multiple scripts, I want to avoid adding this snippet in every shellscript.
Is it possible to do so, in shell script? If so, how?
Thanks
set -x; source kafka-env-parameters.txt; set +x?keyandvalueto persist after the code snippet has been executed, put it into a separate shell script file and run it as a command.