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 $(< file). reopening /dev/stdin mostly works, but easily broken by sudo: # same user. works [root@okdistr ~]# echo aaa | bash -c 'echo $(</dev/stdin)' aaa # different user. fail [root@okdistr ~]# echo aaa | sudo -u nobody bash -c 'echo $(</dev/stdin)' bash: /dev/stdin: Permission denied # spawn new process. not want [root@okdistr ~]# echo aaa | sudo -u nobody bash -c 'echo $(cat)' aaa # try to read from fd: silently fails [root@okdistr ~]# echo aaa | sudo -u nobody bash -c 'echo $(<&0)' # works, but too complex [root@okdistr ~]# echo aaa | sudo -u nobody bash -c 'a=; while true; do rc=0; read -N1024 b || rc=$?; a=$a$b; [ $rc = 0 ] || break; done; echo "$a"' aaa [root@okdistr ~]#