title: Linux Shell Script: Save command outputs in variable/file?
body: <p>I want to use some output of a command, but I don't know, how I can save the output in a variable or file.</p>
  
  <p>The script is connecting to a specified server via telnet and executes different commands. One command is needed for further commands. Well... I have to save these informations from the command output.</p>
  
  <p>My code:</p>
  
  <pre><code>    #!/bin/bash
      (
              echo open server portnumber
              sleep 2s
              echo "login username password"
              sleep 1s
              echo "use sid=1"
  
              CLIENT_LIST=$(echo "clientlist")
  
              sleep 1s
  
              echo "clientupdate client_nickname=Administrator"
  
              for client_id in $(echo $CLIENT_LIST | grep -Eo "clid=[0-9]+" | grep -Eo "[0-9]+"); do
                      echo "clientpoke clid=$client_id msg=How\sare\syou!"
                      sleep 1s
              done
  
              sleep 1s
              echo "logout"
              echo "quit"
      ) | telnet
  </code></pre>
  
  <p>I want to save the output of the command 'clientlist' in a variable or file. A variable would be the best solution. But actually the variable just saves 'clientlist' and not the output of the command. :(</p>
  
  <p>I hope somebody can help me. Thanks in advance! :)</p>
  
  <p>If you want to test it: It's made for TeamSpeak 3 server.</p>