Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.5k
  • 205
  • 1.8k
  • 2.3k
tags
Link
chaos
  • 49.3k
  • 11
  • 127
  • 147
Source Link
q9f
  • 2.4k
  • 8
  • 31
  • 40

How to generate a random string in a profile alias?

I have an alias in my server's /etc/profile which generates a random directory on command, like this:

alias rdir="mkdir -p ./`cat /dev/random | tr -cd 'a-z0-9' | head -c 8`/"

But it turns out this generates always the same string (in this case: directory). I figured out already this seems to be related to source'ing the profile file and only generates a new random string after I call source /etc/profile.

Now, I wonder, how do I generate a random string in an alias which always changes when I call the alias, like in this example: rdir? (Without re-source-ing?)