Random password variable disappears
Posted
by snaken
on Stack Overflow
See other posts from Stack Overflow
or by snaken
Published on 2010-05-06T14:53:48Z
Indexed on
2010/05/06
14:58 UTC
Read the original article
Hit count: 166
Hi,
I'm using the following to generate a random password in a shell script:
DBPASS=</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 8)
When i run this in a file on its own like this:
#!/bin/sh
DBPASS=</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 8)
echo $DBPASS
A password is echoed. When i incorporate it into a larger script though the variable never seems to get created for some reason,
so for example this doesn't work:
DBPASS=</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 8)
sed -i s/oldpass/$DBPASS/ mysql_connect.php
If i manually set the variable though everything is fine..
can anyone see why?
© Stack Overflow or respective owner