LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-30-2010, 12:54 AM   #1
ram87pune
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Rep: Reputation: 0
Scripting problem


Hi guys I have written a script which reads a text file and takes out absolute and relative paths embedded in the text file.Then the script looks for a string in some text files mentioned in those paths.

The problem I am facing is that since these paths are from my working directory,if I try to run the script from a different directory the paths are not read.please help.
 
Old 11-30-2010, 01:48 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
Perhaps you could, oh, I don't know, actually show us the script? Or at least the part of it that seems to be causing the problem.

It would also be nice to get an example of the contents of the input file, and the actual and expected output.
 
Old 11-30-2010, 02:04 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by ram87pune View Post
The problem I am facing is that since these paths are from my working directory,if I try to run the script from a different directory the paths are not read.please help.
Isn't that the whole point of absolute a relative paths?
 
Old 11-30-2010, 02:57 AM   #4
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Well, if such a script is intended to work in every directory you'll have to work with absolute pathes only. If you want to substitute the relative with absolute pathes look at the variables
Code:
$PWD # current working directory
$OLDPWD # previous working directory
Markus
 
Old 11-30-2010, 03:21 AM   #5
ram87pune
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
Isn't that the whole point of absolute a relative paths?
No what I want to say is the text files mentioned in those paths are not read from a different directory.e.g if I am running the script in my home directory say /home/xyz/ then it reads the files which are say /home/xyz/a.txt OR ../xyz/b.txt

But if a different user say /home/abc/ tries to run this script then it won't grep those files
 
Old 11-30-2010, 03:40 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
Hence the term relative paths. That would be an explanation but not a question that can be answered. What is it you would like to do?
And as David has said in post #2, this would go a lot smoother if we actually saw some script?
 
Old 11-30-2010, 03:40 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
EDIT: removing double post
 
Old 11-30-2010, 04:02 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
First thing, if /home/xyz is the same directory for all the users you shouldn't use relative paths at all.

Second: permissions. Is /home/xyz +x and +r for everyone? What about its contents?

If you truly want to use relative paths and "xyz" is a different directory for each user then I don't understand the question.

Are you sure you know what relative and absolute paths are and what their purpose(s) are?

We can't really be of much help unless you provide some more understandable info. We are just guessing.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting problem mastertaf Programming 4 09-19-2008 10:04 AM
Problem in scripting john83reuben Programming 8 02-27-2008 11:24 PM
scripting problem bhert Linux - Newbie 4 10-10-2006 01:24 AM
scripting problem rm filelist milke Programming 9 07-07-2006 06:41 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM


All times are GMT -5. The time now is 08:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration