title: Pass variables from one Bash script to another after SSH
body: <p>Okay, so I am new to bash scripting, about 2 whole hours and I'm banging my head against a wall. I need to carry some variables from one script to another and can't seem to get it to work.</p>
  
  <p>This works fine</p>
  
  <p>script1.sh</p>
  
  <pre><code>echo "Enter your name"
  read name
  export name
  ./script2.sh
  </code></pre>
  
  <p>sript2.sh</p>
  
  <pre><code>echo $name
  </code></pre>
  
  <p>This does not</p>
  
  <p>script1.sh</p>
  
  <pre><code>echo "Enter your name"
  read name
  export name
  ssh $user@$domain "bash -s" &lt; ./script2.sh
  </code></pre>
  
  <p>sript2.sh</p>
  
  <pre><code>echo $name
  </code></pre>
  
  <p>The code is dumb, I get that but basically what I want to do is pass database variables to script 2 to use on the server I've SSH'd into. I would do this all in one script but it seems the only way that I can get the server commands to run is to call a second script after the login, otherwise it runs the server commands locally and fails. I'm doing this from a Mac if that makes any difference at all.</p>
  
  <p>Help?</p>
  
  <p><strong>**</strong> Update with more legitimate code <strong>****</strong></p>
  
  <p>login.sh</p>
  
  <pre><code>#!/bin/bash
  echo "Enter server username:"
  read user
  echo "Enter server domain"
  read domain
  echo "Enter your password"
  read password
  echo "Enter database name"
  read database
  export database
  export user
  export domain
  export password
  ssh $user@$domain "bash -s" &lt; ./create_files.sh 
  </code></pre>
  
  <p>create_files.sh</p>
  
  <pre><code>#!/bin/bash
  cd public_html
  tar -zcvf test.tar.gz test.html
  echo "db:"$database
  mysqldump -u $user -p"$password" $database &gt; $database.sql
  </code></pre>
  
  <p>The goal here is to use the details from login.sh in create_files.sh after this is done I also need to use the login details to scp the created files back to my local machine. Hope this clarifies the problem.</p>