Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How to read a .properties file through script

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 as a basic shell script.

However, there’s a trick to it. If you just run the properties file like so:

sh appl.properties

The assignments will be made at the sub-level, then discarded when the properties file (script) ends execution.

So to get the properties in a calling script, you need to use the “source” command:

. appl.properties

Note that the space after the initial dot is very important!

To reference shell variable assignments, you use the “$” to indicate variable substitution.

So, to put it all together:

# #!/bin/sh
# # Sample shell script to read and act on properties
#
# # source the properties:
# . appl.properties
#
# # Then reference then:
# echo "My name is $name and I'm $age years old."

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x