Reading Java Properties Files from Bash

2004-11-03 / All Blog posts

Ever notice that Java properties files are fairly similar to bash scripts? Here is a short bash script that takes a valid Java properties file called language.properties, massages it into a format that is compatible with bash syntax, writes it to a temporary file and sources it.

TEMPFILE=$(mktemp)
cat language.properties|\
sed -re 's/"/"/'g|sed -re 's/=(.*)/="\1"/g'>$TEMPFILE
source $TEMPFILE
rm $TEMPFILE

After running this script, all of the properties in the Java properties file become available as environment variables.


comments powered by Disqus