Reading a single byte from stdin with Bash?

    I am currently having some pain reading very small amounts of input from stdin with bash. For example I want to be able to just pull the next byte of stdin (as a string). read wants to pull lines.

    I did think of doing something like:
    
    cat - > /tmp/foo
    
    cat /tmp/foo | cut -b 42
    
    
    But the problem with this is that stdin of the bash script I am writing never ends. Perhaps I could so something like:
    
    cat - > /tmp/foo &
    
    cat /tmp/foo | cut -b 42
    
    
    Then I need to be able to handle the scenario when the reader is ahead of the writing, probably by just spinning until the input appears.

    This of course doesn't work as I had expected it to, because the first cat can't be backgrounded because then it looses access to stdin. I need some sort of forking mechanism...

posted at: 07:00 | path: /problemcode | permanent link to this entry

    Add a comment to this post:

    Your name:

    Your email: Email me new comments on this post
      (Your email will not be published on this site, and will only be used to contact you directly with a reply to your comment if needed. Oh, and we'll use it to send you new comments on this post it you selected that checkbox.)


    Your website:

    Comments: