title: bash ldap search - variable as filter
body: <p>I am arguing with something i expected to be simple....</p>
  
  <p>I want to lookup a users manager from ldap, then get the managers email and sam name.</p>
  
  <p>I expected to be able to get the cn for the manager from ldap like this:</p>
  
  <pre><code>manager=$(/usr/bin/ldapsearch -LLL -H ldap://company.ads -x -D admin@company.ads -w password -b ou=employees,dc=company,dc=ads sAMAccountName=employee1 | grep "manager:" | awk '{gsub("manager: ", "");print}' | awk 'BEGIN {FS=","}; {print $1, $2 }' )
  </code></pre>
  
  <p>that gives me the cn like this:</p>
  
  <pre><code>CN=manager,\ Surname
  </code></pre>
  
  <p>Now when I run another query like this:</p>
  
  <pre><code>/usr/bin/ldapsearch -LLL -H ldap://company.ads -x -D admin@company.ads -w password -b ou=employees,dc=company,dc=ads $manager 
  </code></pre>
  
  <p>I get bad search filter (-7) echo the command copy, paste run it i get the record back....</p>
  
  <p>Ive tried a number of variations on this, can anyone see what im missing?</p>
  
  <p>Thanks.</p>