title: Save kafka broker ids (zookeeper-shell.sh result) to variable in bash script
body: <p>I want to check if broker id is already in use, but I want to do this within a script.</p>
  
  <pre><code>./bin/zookeeper-shell.sh localhost:2181 &lt;&lt;&lt; "ls /brokers/ids"
  </code></pre>
  
  <p>Gives the result I want, but how would I save this to a variable for later use? What I'm interested in is the actual result of the "ls ..". The whole output includes some fodder:</p>
  
  <pre><code>Connecting to localhost:2181
  Welcome to ZooKeeper!
  JLine support is disabled
  
  WATCHER::
  
  WatchedEvent state:SyncConnected type:None path:null
  Node does not exist: /brokers/ids
  </code></pre>
  
  <p>If I save the result to a variable I actually only get this fodder and the last line is only printed to the screen.</p>
  
  <pre><code>var=$(./opt/kafka/bin/zookeeper-shell.sh localhost:2181 &lt;&lt;&lt; "ls /brokers/ids")
  </code></pre>
  
  <p>And then echo $var gives</p>
  
  <pre><code>Connecting to localhost:2181 Welcome to ZooKeeper! JLine support is disabled WATCHER:: WatchedEvent state:SyncConnected type:None path:null
  </code></pre>
  
  <p>How would I get the actual result of the request to a variable for later use?</p>