Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 11th, 2011, 02:51 PM
reference2me reference2me is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 22 reference2me User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 5 m 10 sec
Reputation Power: 0
Property file error

I am reading property file from shell script as below

Code:
#!/bin/sh
 
# 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.

Reply With Quote
  #2  
Old June 11th, 2011, 09:39 PM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 41 m
Reputation Power: 1485
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Property file error

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap