title: Pipe output to bash function
body: <p>I have as simple function in a bash script and I would like to pipe stdout to it as an input.</p>
  
  <pre><code>jc_hms(){
    printf "$1"
  }
  </code></pre>
  
  <p>I'd like to use it in this manner.</p>
  
  <pre><code>var=`echo "teststring" | jc_hms`
  </code></pre>
  
  <p>Of course I used redundant functions echo and printf to simplify the question, but you get the idea.  Right now I get a "not found" error, which I assume means my parameter delimiting is wrong (the "$1" part).  Any suggestions?</p>
  
  <p>Originally the jc_hms function was used like this:</p>
  
  <pre><code>echo `jc_hms "teststring"` &gt; //dev/tts/0
  </code></pre>
  
  <p>but I'd like to store the results in a variable for further processing first, before sending it to the serial port.</p>
  
  <p>EDIT:
  So to clarify, I am NOT trying to print stuff to the serial port, I'd like to interface to my bash functions should the "|" pipe character, and I am wondering if this is possible.</p>
  
  <p>EDIT: Alright, here's the full function.</p>
  
  <pre><code>jc_hms(){
    hr=$(($1 / 3600))
    min=$(($1 / 60))
    sec=$(($1 % 60))
  
    printf "$hs:%02d:%02d" $min $sec
  }
  </code></pre>
  
  <p>I'm using the function to form a string which come this line of code</p>
  
  <pre><code>songplaytime=`echo $songtime | awk '{print S1 }'`
  printstring="`jc_hms $songplaytime`"  #store resulting string in printstring
  </code></pre>
  
  <p>Where $songtime is a string expressed as "playtime totaltime" delimited by a space.</p>
  
  <p>I wish I can just do this in one line, and pipe it after the awk</p>
  
  <pre><code>printstring=`echo $songtime | awk '{print S1 }' | jc_hms`
  </code></pre>
  
  <p>like so.</p>