Results 1 to 4 of 4
Hey,
I got stuck coding a small bash script which creates a php file.
This is what I have so far but it seems not to be working:
Code:
#!/bin/bash
...
- 11-02-2011 #1Just Joined!
- Join Date
- Nov 2011
- Posts
- 2
Echo Bash Variable to create PHP file.
Hey,
I got stuck coding a small bash script which creates a php file.
This is what I have so far but it seems not to be working:
When I edit userpass.php I see:Code:#!/bin/bash userid=</dev/urandom tr -dc A-Za-z0-9 | head -c 16 passid=</dev/urandom tr -dc A-Za-z0-9 | head -c 24 echo '<?php $tempuid = "$userid"; $temppid = "$userid"; //php actions below. ?>' > userpass.php
Instead of the value of the variables.PHP Code:<?php
$tempuid = "";
$temppid = "";
//php actions below.
?>
Thanks
- 11-02-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
Your first two commands are not putting the values into the variables, you need to use $() or `` to capture the command output.
When you echo the php code you need to use double-quotes in order to allow the variable expansion to happen. You'll also need to escape the PHP variable names, too.
e.g.:
Code:#!/bin/bash #userid=</dev/urandom tr -dc A-Za-z0-9 | head -c 16 userid=$(</dev/urandom tr -dc A-Za-z0-9 | head -c 16) #passid=</dev/urandom tr -dc A-Za-z0-9 | head -c 24 passid=$(</dev/urandom tr -dc A-Za-z0-9 | head -c 24) echo "userid: $userid" echo "passid: $passid" echo "<?php \$tempuid = \"$userid\"; \$temppid = \"$userid\"; //php actions below. ?>" > userpass.php
- 11-02-2011 #3Just Joined!
- Join Date
- Nov 2011
- Posts
- 2
Thanks, finally after hours of trying and failing.
- 11-02-2011 #4Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
np, been there done that. glad it got sorted.


Reply With Quote