substitution "read all from fd" silently fails: $(<

2015-07-01 Thread Ilya Basin
Hi list. Want to read whole stdin into variable. Don't want to spawn new processes (cat). Don't want to reopen existing fd &0 First thing I tried: $(<&0) It silently returns an empty string. From bash manual: The command substitution $(cat file) can be replaced by the equivalent but faster

Re: substitution "read all from fd" silently fails: $(<

2015-07-01 Thread Greg Wooledge
On Wed, Jul 01, 2015 at 10:19:10PM +0300, Ilya Basin wrote: > Want to read whole stdin into variable. > Don't want to spawn new processes (cat). If the data stream does not contain any NUL bytes, you can use: IFS= read -r -d '' variable

Re: substitution "read all from fd" silently fails: $(<

2015-07-01 Thread Geir Hauge
On Wed, Jul 01, 2015 at 10:19:10PM +0300, Ilya Basin wrote: > Hi list. > > Want to read whole stdin into variable. > Don't want to spawn new processes (cat). > Don't want to reopen existing fd &0 > > First thing I tried: $(<&0) > It silently returns an empty string. This type of query is prefera

Re: substitution "read all from fd" silently fails: $(<

2015-07-01 Thread Stephane Chazelas
2015-07-01 22:19:10 +0300, Ilya Basin: > Hi list. > > Want to read whole stdin into variable. > Don't want to spawn new processes (cat). [...] Note that $(&3), it doesn't work in ksh either, (in ksh, like in bash, $(

Re[2]: substitution "read all from fd" silently fails: $(<

2015-07-01 Thread Ilya Basin
SC> 2015-07-01 22:19:10 +0300, Ilya Basin: >> Hi list. >> >> Want to read whole stdin into variable. >> Don't want to spawn new processes (cat). SC> [...] SC> Note that SC> $( execute /bin/cat in that process, it does the reading (from SC> file) and writing (to the pipe) by itself (and the paren

Re: substitution "read all from fd" silently fails: $(<

2015-07-01 Thread Pádraig Brady
On 01/07/15 22:48, Stephane Chazelas wrote: > 2015-07-01 22:19:10 +0300, Ilya Basin: >> Hi list. >> >> Want to read whole stdin into variable. >> Don't want to spawn new processes (cat). > [...] > > Note that > > $( execute /bin/cat in that process, it does the reading (from > file) and writing (