I'm parsing a file with key=value
data and then export them as environment variables. My solution works, but not with special characters, example:
.data
VAR1=abc
VAR2=d#r3_P{os-!kblg1$we3d4xhshq7=mf$@6@3l^
script.sh
#!/bin/bash
while IFS="=" read -r key value; do
case "$key" in
'#'*) ;;
*)
eval "$key=\"$value\""
export $key
esac
done < .data
$ . ./script.sh
Output:
$ echo $VAR1
abc
$ echo $VAR2
d#r3_P{os-!kblg1=mf6@3l^
but should be: d#r3_P{os-!kblg1$we3d4xhshq7=mf$@6@3l^