1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Rep Power

    Property file error

    I am reading property file from shell script as below

    # source the properties:
    . ./appl.properties
    # Then reference then:
    echo "My name is $name and I'm $age years old."
    But my property file path is different in development and production environment.

    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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Rep Power
    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

IMN logo majestic logo threadwatch logo seochat tools logo