The question could probably be reworded. What I would like to have is certain path, say /workingsrc to refer to a different real path per shell (bash) instance simultaneously.

So in an instance of bash I can do ls /workingsrc and get the contents of /foo/bar and in another instance that is running at the same time in the same machine do ls /workingsrc and get the contents of /foo/zoo.

Do you know if there is a way to do this? I'm using linux and bash.

link|improve this question
feedback

2 Answers

up vote 1 down vote accepted

Variant symlinks is what you want, but are only on *BSD and AFS filesystem. Working with environment variables is much easier (see Hyppy response).

link|improve this answer
You are right, this is exactly what I was looking for. Too bad they are not available in Linux. – Jacobo de Vera Mar 18 '11 at 13:51
feedback

You can probably do this with environment variables. For example: Shell 1:

WORKINGSRC=/foo/bar
ls $WORKINGSRC

Shell 2:

WORKINGSRC=/foo/zoo
ls $WORKINGSRC

Back on shell 1:

ls $WORKINGSRC

You should still see /foo/bar on shell 1, even after setting the variable to a different value in shell 2.

link|improve this answer
You could probably add an alias to this so you don't distract people with the $ – Decado Mar 18 '11 at 13:21
An alias doesn't expand within a command unless it begins with the alias, though. For example, if you set $WORKINGSRC to an alias called aliaswrksrc, then "ls aliaswrksrc" won't work. You'd have to make a separate alias for each command you want to do, unless I'm mistaken. – Hyppy Mar 18 '11 at 13:24
Okay, i meant it's set to the correct value when you log into the shell. So as part of .bash_profile you do: export WORKING_DIR=/var/tmp; alias cdwork="cd $WORKING_DIR". Then cdwork will take me to what WORKING_DIR is set to at login to the shell time. – Decado Mar 18 '11 at 13:36
yes, currently I am using a env var with the work dir path in it, and a function that sets its value and updates all depending env vars. I also have shopt -s cdable_vars in my .bashrc so that I can do cd workingsrc anywhere and get to $workingsrc. I was looking for a next step from this setup. – Jacobo de Vera Mar 18 '11 at 13:43
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.