title: Bash store command PID in variable and kill process
body: <p>I would like to use a shell script in order to establish ethernet connection. </p>
  
  <p>I am using a function implemented as :</p>
  
  <pre><code>function connec()
  {
      ip link set eth0 up
      sleep 5
      udhcpc -i eth0
      pid=$$
      echo $pid
      ps 
      kill -9 $pid
  }
  </code></pre>
  
  <p>However, the script returns : </p>
  
  <pre><code>743
  743 root      2704 S    {script.sh} /bin/bash ./script.sh connect
  767 root      2200 S    udhcpc -i eth0
  Killed
  </code></pre>
  
  <p>I don't succeed in store 767 rather than 743. I also tried by using $! but in that specific case "echo $pid" returns 0. </p>