0

I have a bunch of web resources. To make my life easier I have made now an additional one which returns aliases for all the endpoints. This is quite handy as I also do have different environments (host names and ports). Now I can curl the resource and copy paste all aliases (like list="curl ...") which works fine. But how can I source the aliases directly? Something like

curl "http://localhost:9999/env" | bash

which btw does not work.

EDIT: sample output

alias topics='curl -X GET "http://localhost:9999/bus/api/v1/topics"'
alias stats='curl -X GET "http://localhost:9999/bus/api/v1/topics+stats"'
KIC
  • 5,887
  • 7
  • 58
  • 98

1 Answers1

2

Just guessing, but I'm pretty sure it will work:

source <(curl "http://localhost:9999/env")

I'm not sure about the curl syntax, I'm just mimmicking yours. You need curl to return in its standard output the contents that have to be processed by bash.

Poshi
  • 5,332
  • 3
  • 15
  • 32
  • this indeed works, now I just put an alias for this into my bashrc :-) – KIC Jul 12 '18 at 18:32
  • 2
    This does indeed work. However, there's a [known issue in Bash 3.2](https://stackoverflow.com/questions/32596123/why-source-command-doesnt-work-with-process-substitution-in-bash-3-2) making it fail on macOS. In that case, `eval "$(curl "http://localhost:9999/env")"` is an alternative. – that other guy Jul 12 '18 at 18:32
  • @thatotherguy Don't you have to escape some characters? – Poshi Jul 12 '18 at 18:43
  • Nope, `"` doesn't need additional escaping inside `$(..)` – that other guy Jul 12 '18 at 18:45