0

I am trying to make some aliases to make my workflow easier, and I'm having some issues with variables resolving too quickly.

This example helps illustrate the issue:

# ~/.zshrc
export WORKSPACEHOST="localhost"
alias swloc="export WORKSPACEHOST='localhost'"
alias swrem1="export WORKSPACEHOST='16.42.42.192'"
alias swrem2="export WORKSPACEHOST='16.42.43.12'"

alias getclusterinfo="curl -X http://$WORKSPACEHOST:3080/info > /tmp/info.json; open /tmp/info.json"
... And a bunch more of these types of commands

The intention is that I can use swrem1 to switch the functionality of getclusterinfo, but it turns out that getclusterinfo is hard set to localhost at the time of the sourcing of ~/.zshrc.

What is the correct way to solve this so that aliases lazily reference the current value of the environment variable?

SwimBikeRun
  • 4,192
  • 11
  • 49
  • 85

0 Answers0