Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Echo Bash Variable to create PHP file.


    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:
    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
    When I edit userpass.php I see:
    PHP Code:
    $temppid "";
    //php actions below.
    Instead of the value of the variables.


  2. #2
    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.


    #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

  3. #3
    Thanks, finally after hours of trying and failing.

  4. $spacer_open
  5. #4
    np, been there done that. glad it got sorted.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts