June 11th, 2011, 02:51 PM
Property file error
I am reading property file from shell script as below
But my property file path is different in development and production environment.
# source the properties:
# Then reference then:
echo "My name is $name and I'm $age years old."
both my shell script and property file stay in same location.
hence, i am giving relative path to fetch properties file. Lets say the files exist in folder A/test/shell/test
here if i execute the script from shell folder it is working fine. where A, test, shell are folders
when i execute the script from test folder like ./shell/test.sh, it is throwing the error saying "appl.properties file not found"
please let me know i there is a mistake here.
June 11th, 2011, 09:39 PM
It's down to relative directories of where your current working directory is, not where the script you run is.
If the script (and it's config file) are in the same directory as each other and your shell is also in that directory (as shown with pwd and being able to run the script with ./test.sh) then the relative path of ./appl.properties will be found. When you go back one directory (so you need to use ./shell/test.sh) the config file is not longer in the current directory, so the ./ part of the relative path in your script will fail to find the file.
You can do things with the $0 variable and which and other such commands to find out the directory in which the command running resides, and hence the directory where the config file is.
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc