There is a little In / Out bash sample:
1st drug:
tmpfile=$(mktemp /tmp/adb-XXXXXXXXX) exec 5> >(adb shell >$tmpfile) exec 6<$tmpfile rm $tmpfile
Then you can write &5 and read from &6 :
read -t .1 -u 6 foo;echo $foo shell@HWY625-U :/ $ read -t .1 -u 6 foo;echo $foo echo date >&5 read -t .1 -u 6 foo;echo $foo date read -t .1 -u 6 foo;echo $foo Sat Dec 17 18:20:35 CET 2016
Nota: I rm $tmpfile for security reasons, but as long as the descriptors remain open, you can use them (the timeout read option works fine with the while ):
>&5 echo uptime while read -t .1 -u 6 foo;do echo $foo;done uptime up time: 08:16:42, idle time: 01:20:19, sleep time: 06:47:13
and
ls -l $tmpfile ls: cannot access /tmp/adb-hbmJrFVX4: No such file or directory ls -l /proc/self/fd total 0 lrwx------ 1 user user 64 Dec 17 18:24 0 -> /dev/pts/8 l-wx------ 1 user user 64 Dec 17 18:24 1 -> pipe:[22316547] lrwx------ 1 user user 64 Dec 17 18:24 2 -> /dev/pts/8 l-wx------ 1 user user 64 Dec 17 18:24 5 -> pipe:[22316558] lr-x------ 1 user user 64 Dec 17 18:24 6 -> /tmp/adb-hbmJrFVX4 (deleted)
When finished, close all:
>&5 echo exit while read -t .1 -u 6 foo;do echo $foo;done exit exec 5>&- exec 6<&-
source share