0

I've tried this:

echo $RANDOM | md5sum | head -c 20 | { read val; sed -i 's/__SALT__/$val/g' app.txt; }

But this replaces __SALT__ with the string $val instead of the value in the variable.

geoidesic
  • 101
  • 2
  • Do note there are only 32768 possible values for salt in this case... – frostschutz Jan 24 '22 at 21:58
  • if you want a sensible salt, you should read `/dev/urandom` instead of using the shell's `$RANDOM`. For a random 80-bit salt, you could use `head -c10 /dev/urandom | md5sum | head -c20`. (Or something with `od` to make the hexdump, since getting the MD5 hash of a random byte string is pretty much unnecessary.) – ilkkachu Jan 24 '22 at 22:22

1 Answers1

0

Found the solution here: Passing a variable to sed

Just needs double quotes:

echo $RANDOM | md5sum | head -c 20 | { read val; sed -i "s/__SALT__/$val/g" app.txt; }
geoidesic
  • 101
  • 2