title: How do I pass arguments to a defined function in a shell script?
body: <p>I'm trying to create a function wherein I pass two dates as arguments and get their day of the week out. I've gotten it to work by copying and pasting the parsing process for both input dates, but I'm trying to save space by condensing the process into a defined function. The input should look like so:</p>
  
  <pre><code>datematch.sh 01/03/1984 06/12/2008
  </code></pre>
  
  <p>But I keep getting error messages along the lines of:</p>
  
  <pre><code>./birthday_match.sh: line 9: ${$1:0:2}: bad substitution
  ./birthday_match.sh: line 9: ${$1:0:2}: bad substitution
  The first person was born on: 
  The second person was born on: 
  Thus, they were born on the same day.
  </code></pre>
  
  <p>How am I substituting wrong? The full code is below.</p>
  
  <pre><code>#!/bin/bash
  var1=$1
  var2=$2
  if [ "$#" -ne 2 ]; then
      echo "illegal number of birthdays"
  else
      function get_dayname () 
      {
          mo=${$1:0:2}
          dy=${$1:3:2}
          yr=${$1:6:4}
          combo="${mo}${dy}0000${yr}"
          fulldate="$(date $combo 2&gt; /dev/null)"
          wkdy=${fulldate:0:3}
          eval $wkdy
      }
      first=$(get_dayname "$var1")
      second=$(get_dayname "$var2")
      echo "The first person was born on: $first"
      echo "The second person was born on: $second"
      if [ "$first" == "$second" ]; then
          echo "Thus, they were born on the same day."
      else
          echo "Thus, they were not born on the same day."
      fi
  fi
  </code></pre>