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.
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; }
/dev/urandom
instead of using the shell's$RANDOM
. For a random 80-bit salt, you could usehead -c10 /dev/urandom | md5sum | head -c20
. (Or something withod
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