title: AWK adding digits in a number which represents result of a command
body: <p>I'm trying to learn bash shell scripting and awk, and I wrote some simple code that loops through the arguments given, and if params contain digits, I print the digits only.</p>
  
  <p>Next, using AWK, I would to add them one by one and print the sum. And I'm stuck here. This is my code:</p>
  
  <pre><code>#!/bin/bash
  
  for user in "$@"
  do
    echo "$user"
    if [[ $user =~ [0-9]+ ]]; then
      usersDigits=$(echo $user | tr -dc '0-9')
      echo "$usersDigits"
      echo "has digits"
      echo $(awk '{ sum+=$usersDigits } END { print sum }')
    else
      echo "doesn't have digits"
    fi
  done
  </code></pre>
  
  <p>What am I doing wrong?</p>