title: Using Awk with escape characters inside a Bash script
body: <p>I'm working on a shell script (using Bash) for Linux systems.</p>
  
  <p>As part of this script I'm using awk to get the percentage of packets dropped from a ping request. This works fine when executed from the terminal shown below:</p>
  
  <pre><code>test=`ping gnu.org -c10 | tail -2`; echo $test | awk '{printf $6 "\b"}'
  </code></pre>
  
  <p>This gets the percentage of packets dropped and echos it using the backspace escape character to show just "0" rather tan "0%" - this is as the value is used later on as an integer value.</p>
  
  <p>Inside the script, the code looks like this:</p>
  
  <pre><code>#Pings the gateway ten times and stores the result
  local pingResults=`ping -c10 $gateway | tail -2`
  
  #Uses awk to get the percentage of packets lost using \b to remove the %
  local packetsLost=`echo $pingResults | awk '{printf $6 "\b"}'`
  </code></pre>
  
  <p>I return the value from packetsLost and echo it and it gives "0%", totally ignoring the \b</p>
  
  <p>Could somebody please explain why this is happening inside the shell script and how I can remedy this?</p>
  
  <p>I understand there are alternatives such as using cut but I'd like to keep the line as simple and efficient as possible.</p>