Mike Slinn
Mike Slinn

Reading Java Properties Files from Bash

Published 2004-11-03.

This article is categorized under Java, Scripting

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.

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

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