0

Here is an alias I made on my ~/.bashrc:

alias rand="echo $(curl -s https://whatthecommit.com/index.txt)"

If you enter this url, it simply returns a random message every request, as intended.

But if you use this alias from command line:

rand

it'll always returns the same message, instead of making a new http request, as if it's caching the previous result for some reason.

BUT, if you call it directly on terminal as:

echo $(curl -s https://whatthecommit.com/index.txt)

It makes a different call every time.

Why is this happening? And how to fix it?

João
  • 134

1 Answers1

0
alias rand="echo \$(curl -s https://whatthecommit.com/index.txt)"   

Will do what you want; without that \ it will do the $(...) once,
when the alias is "defined", not as it is used (later, what you want).

Define the alias with both variants on the command line
and then type alias after each
and you will see and realize the effect.

Hannu
  • 6,605
  • 1
  • 28
  • 45