LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-02-2012, 08:18 PM   #1
xafwodahs
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Rep: Reputation: 0
Changing paths with eval and a script


I work on multiple copies of a complex project simultaneously. To ease navigation, I use aliases to "cd" to the paths I use most often.

I cannot hardcode absolute paths, however, because each copy of the project has a different parent directory, e.g.

/home/me/proj/work1/...<full project>
/home/me/proj/work2/...<full project>

The root of each project is identifiable by a .git directory. (This is a simplified description - yes, I know git can save me the trouble of having multiple copies of the same project).

So I have a "findroot" script that walks up until it finds the .git. And it can take a new destination path...

/home/me/proj/work1/path/to/some/area$ findroot
cd ../../../../
/home/me/proj/work1/path/to/some/area$ findroot path/to/new/area
cd ../../../../path/to/new/area

Then I eval that script so that I can change the directory in the calling shell, e.g.
$ alias cdroot='eval `findroot $*`'

The problem is, that the $* seems to get ignored. If I do:

/home/me/proj/work1/path/to/some/area$ cdroot path/to/new/area
/home/me/proj/work1$

It only goes to the root and ignores path/to/new/area.

How do I get the argument to cdroot to get passed in as the argument to findroot via the $* ?

Any help would be appreciated.
 
Old 03-02-2012, 09:23 PM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
To pass variables between shells, you are better to use environment variables.
My suggestion is to get the output from your findroot script into an environment variable and then use that in your alias.
NEWROOT=$(findroot path/to/new/area)
alias cdroot='cd $NEWROOT'
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script to read paths Christos Badogias Linux - Newbie 11 11-06-2011 08:51 AM
Creating a bash script which understands paths to files en8scl Linux - Newbie 9 05-21-2006 07:22 PM
Changing PATHS Murdock1979 Slackware 2 07-27-2005 08:02 PM
Changing PATHS Azfer Linux - Newbie 5 09-08-2004 01:59 AM
Automatically resolving WINDOWS paths to pre-configured Linux paths gazzy Linux - General 1 09-05-2003 10:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:00 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
Open Source Consulting | Domain Registration