Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The solutions mentioned above will work for the basics. I don't think they cover multi-line values though. Here is an awk program that will parse Java properties from stdin and produce shell environment variables to stdout:</p> <pre><code>BEGIN { FS="="; print "# BEGIN"; n=""; v=""; c=0; # Not a line continuation. } /^\#/ { # The line is a comment. Breaks line continuation. c=0; next; } /\\$/ &amp;&amp; (c==0) &amp;&amp; (NF&gt;=2) { # Name value pair with a line continuation... e=index($0,"="); n=substr($0,1,e-1); v=substr($0,e+1,length($0) - e - 1); # Trim off the backslash. c=1; # Line continuation mode. next; } /^[^\\]+\\$/ &amp;&amp; (c==1) { # Line continuation. Accumulate the value. v= "" v substr($0,1,length($0)-1); next; } ((c==1) || (NF&gt;=2)) &amp;&amp; !/^[^\\]+\\$/ { # End of line continuation, or a single line name/value pair if (c==0) { # Single line name/value pair e=index($0,"="); n=substr($0,1,e-1); v=substr($0,e+1,length($0) - e); } else { # Line continuation mode - last line of the value. c=0; # Turn off line continuation mode. v= "" v $0; } # Make sure the name is a legal shell variable name gsub(/[^A-Za-z0-9_]/,"_",n); # Remove newlines from the value. gsub(/[\n\r]/,"",v); print n "=\"" v "\""; n = ""; v = ""; } END { print "# END"; } </code></pre> <p>As you can see, multi-line values make things more complex. To see the values of the properties in shell, just source in the output:</p> <pre><code>cat myproperties.properties | awk -f readproperties.awk &gt; temp.sh source temp.sh </code></pre> <p>The variables will have '_' in the place of '.', so the property some.property will be some_property in shell.</p> <p>If you have ANT properties files that have property interpolation (e.g. '${foo.bar}') then I recommend using Groovy with AntBuilder.</p> <p>Here is <a href="http://shrubbery.mynetgear.net/c/display/W/Reading+Java-style+Properties+Files+with+Shell" rel="noreferrer">my wiki page on this very topic</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload