{"id":2407,"date":"2017-12-08T09:35:42","date_gmt":"2017-12-08T09:35:42","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2407"},"modified":"2020-01-09T09:54:01","modified_gmt":"2020-01-09T09:54:01","slug":"how-to-read-a-properties-file-through-script","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-read-a-properties-file-through-script\/","title":{"rendered":"How to read a .properties file through script"},"content":{"rendered":"<p><strong>rajeshkumar created the topic: How to read a .properties file through script<\/strong><\/p>\n<p>The easy way to do it is to note that a Java properties file has the same format as a basic shell script.<\/p>\n<p>However, there&#8217;s a trick to it. If you just run the properties file like so:<\/p>\n<p>sh appl.properties<\/p>\n<p>The assignments will be made at the sub-level, then discarded when the properties file (script) ends execution.<\/p>\n<p>So to get the properties in a calling script, you need to use the &#8220;source&#8221; command:<\/p>\n<p>. appl.properties<\/p>\n<p>Note that the space after the initial dot is very important!<\/p>\n<p>To reference shell variable assignments, you use the &#8220;$&#8221; to indicate variable substitution.<\/p>\n<p>So, to put it all together:<\/p>\n<p><code># #!\/bin\/sh<br \/>\n# # Sample shell script to read and act on properties<br \/>\n#<br \/>\n# # source the properties:<br \/>\n# . appl.properties<br \/>\n#<br \/>\n# # Then reference then:<br \/>\n# echo \"My name is $name and I'm $age years old.\"<\/code><\/p>\n<p>Regards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rajeshkumar created the topic: How to read a .properties file through script The easy way to do it is to note that a Java properties file has the same format&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[454],"tags":[278],"class_list":["post-2407","post","type-post","status-publish","format-standard","hentry","category-shell-script","tag-script"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2407"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2407\/revisions"}],"predecessor-version":[{"id":2408,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2407\/revisions\/2408"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}