title: Shell - calling function with nc -c
body: <p>This is my Server-Code for now.
  I just want to get Data from a Client, analyze it and send my answer.
  Is there a way to call my function managedata() in nc? My Code, obviously doesn't work.</p>
  
  <p>server.sh:</p>
  
  <pre><code>managedata()
  {
  echo $1
  #do something with data
  return $1
  }
  
  listen()
  {
  echo "Server listening.."
  nc -l -p 1234 -c '$(read i &amp;&amp; managedata $i &amp;&amp; echo $?)'
  }
  
  #MAIN
  while true;
  do
  listen
  done
  </code></pre>
  
  <p>Client.sh:</p>
  
  <pre><code>send()
  {
  echo $1 | nc $ip $port -o 0
  }
  
  #
  register()
  {
  read -p "Login: " usrname
  echo -n "Password: "
  read -s password | shasum &gt; password
  
  #Schleife zum encrypten des Passworts
  #Count = n -&gt; Leslie Lamport Alogrithmus
  n=5
  count=$n
  while [ $count -ge 2 ]
  do
      password="$(cat password | shasum)"
      ((count--))
  done
  
  password=`cat password`
  echo
  echo $password
  
  data="reg-$usrname-$n-$password"
  
  send $data
  }
  
  #
  log()
  {
  echo "..."
  }
  
  #
  menue()
  {
  echo "====== Lab: Shell Programming (BS) ======"
  echo "  r   Register"
  echo "  l   Login"
  echo "  q   Quit"
  echo
  
  read -p "your choice: " check
  
  case "$check" in
      r) register;;
      l) log;;
      q) exit;;
  esac
  
  }
  
  
  #MAIN
  ip=$1
  port=$2
  
  while true
  do
  menue
  done
  </code></pre>
  
  <p>bash -x server.sh:</p>
  
  <pre><code>+ true
  + listen
  + echo 'Server listening..'
  Server listening..
  + nc -l -p 1234 -c '$(read i &amp;&amp; managedata $i &amp;&amp; echo $?)'
  sh: 1: managedata: not found
  + true
  + listen
  + echo 'Server listening..'
  Server listening..
  + nc -l -p 1234 -c '$(read i &amp;&amp; managedata $i &amp;&amp; echo $?)'
  </code></pre>