LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Changing paths with eval and a script (https://www.linuxquestions.org/questions/linux-general-1/changing-paths-with-eval-and-a-script-932421/)

xafwodahs 03-02-2012 08:18 PM

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.

allend 03-02-2012 09:23 PM

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'


All times are GMT -5. The time now is 12:39 AM.