I created this alias in my .bashrc file:
alias changepath="export PATH=$JAVA_HOME/bin:$PATH"
What I want to do is change $JAVA_HOME and then change the $PATH to include the new $JAVA_HOME/bin.
When I change $JAVA_HOME and type this command instead of using the alias, it works as expected.
However, when I change $JAVA_HOME and then use the alias, the changepath command prepends the old $JAVA_HOME/bin instead of the new $JAVA_HOME/bin to $PATH.
How can I fix this?
You can also defer evaluation of variables by single-quoting your alias definition, i.e.
alias changepath='export PATH=$JAVA_HOME/bin:$PATH'
Note that the alias or function solutions do not solve the problem of clearing any previous JAVA_HOME you have set.
So you can wind up with a crazy PATH
PATH="/usr/bin:/sys"
PATH=/usr/bin/java:/usr/bin:/sys
PATH=/usr/bin/java/bin:/usr/bin/java:/usr/bin:/sys
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With