Peng Yu
2018-02-22 04:31:16 UTC
Hi,
The `read` in the following example is not able to read from the stdin
of the script.
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
(
while read -r i
do
echo "$i"
done
) &
wait
$ seq 3 | ./main.sh
I come up with the following solution using a fifo.
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
fifo=$(mktemp -u)
mkfifo "$fifo"
cat < /dev/stdin > "$fifo" &
(
while read -r i
do
echo "$i"
done < "$fifo"
) &
wait
$ seq 3 | ./main.sh
1
2
3
Does anybody have any better way to solve this problem? Thanks.
The `read` in the following example is not able to read from the stdin
of the script.
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
(
while read -r i
do
echo "$i"
done
) &
wait
$ seq 3 | ./main.sh
I come up with the following solution using a fifo.
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
fifo=$(mktemp -u)
mkfifo "$fifo"
cat < /dev/stdin > "$fifo" &
(
while read -r i
do
echo "$i"
done < "$fifo"
) &
wait
$ seq 3 | ./main.sh
1
2
3
Does anybody have any better way to solve this problem? Thanks.
--
Regards,
Peng
Regards,
Peng