I have a file like
name1=value1
name2=value2
I need to read this file using shell script and set variables
$name1=value1
$n
Improved version of @robinst
read_properties()
{
file="$1"
while IFS="=" read -r key value; do
case "$key" in
'#'*) ;;
*)
eval "$key=\"$value\""
esac
done < "$file"
}
Changes:
A nice one is also the solution of @kurumi, but it isn't supported in busybox
And here a completely different variant:
eval "`sed -r -e "s/'/'\\"'\\"'/g" -e "s/^(.+)=(.+)\$/\1='\2'/" $filename`"
(i tried to do best with escaping, but I'm not sure if that's enough)