[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why `echo -n hello | while read v; do echo $v; done' prints nothing?
|
From: |
Stephane CHAZELAS |
|
Subject: |
Re: Why `echo -n hello | while read v; do echo $v; done' prints nothing? |
|
Date: |
Mon, 6 Dec 2010 20:39:57 +0000 (UTC) |
|
User-agent: |
slrn/pre1.0.0-18 (Linux) |
2010-12-2, 19:04(+08), Clark J. Wang:
> Following command also prints nothing, confused :(
>
> for ((i = 0; i < 10; ++i)); do echo -n " $i"; done | while read v; do echo
> $v; done
>
Basically, if you want the equivalent of "cat" (if we let aside
null bytes and performance), you'd need:
while IFS= read -r v; do
printf '%s\n' "$v"
done
[ -z "$v" ] || printf %s "$v"
--
Stephane