On Sun, 2018-08-12 at 00:48 +0200, tomas@tuxteam.de wrote: > On Sat, Aug 11, 2018 at 06:08:34PM -0400, Jim Popovitch wrote: > > Hello! > > > > What's the best way to grab anything that's in stdin into a > > variable > > inside a bash script, but won't block if stdin is null? > > I think read is your friend (at least in bash). It has an option > -t <timeout>, which you can set to zero, for it to just grab what's > available at the moment without waiting (cf "help read" while in > the bash for more details, like setting a delimiter, etc.) > > HTH > -- tomás Thanks for the reply tomás. I'm trying to avoid using read because of the 1 sec minimum timeout. This may seem odd, but 1 sec is 100+ times longer than grep'ing/awk'ing/sed'ing the contents of a variable, so I'm trying to find a faster way to read stdin. -Jim P.
Attachment:
signature.asc
Description: This is a digitally signed message part