1

I'm a bash newb; just curious if this is possible...

assume i have ~/.bash_profile (mac terminal) w/ following declarations:

export src=~/Developer/src
export myapp=$src/myapp

alias buildapp='build $myapp' # just an example...

this gets loaded when i start up the terminal, and everything's fine.

what i want to do is, later when i switch to a different branch/depot/whatever, i want to type,

export src=~/Developer/temp_src

in the shell, and make $myapp automatically reference the new $src variable...

is this actually possible?

1
  • 3
    The simple answer is that this isn't possible with variables. They don't remember the expression used to assign them, and can't re-evaluate it dynamically. Commented Jun 2, 2016 at 21:59

1 Answer 1

2

Don't create myapp variable and just use this alias:

alias buildapp='build "$src/myapp"'

Having said that, it is usually better to use a function instead of alias:

buildapp() { build "$src/myapp"; }
Sign up to request clarification or add additional context in comments.

2 Comments

i thought of that, but hoped to avoid it because... i have 4-5 different variables all depending on $src, and each of them is fairly long (20-30 chars; e.g. $src/foo/bar/baz/whararara/....); and then i have bunch of aliases that reference any of those 4-5...
If possible, you can put all variable assignments based on $src inside this function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.