Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005
From: Michael Tosch (eedmit_at_NO.eed.SPAM.ericsson.PLS.se)
Date: 05/02/05
- Next message: Kenny McCormack: "Re: Usenet (Was: Re: CRON : Can you send values to CRON and get a result ?)"
- Previous message: matt_left_coast: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- In reply to: Stephane CHAZELAS: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Next in thread: Heiner Steven: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 02 May 2005 22:02:57 +0200
Stephane CHAZELAS wrote:
> 2005-04-30, 17:43(+02), Heiner Steven:
>
...
>> The following commands suppress this behaviour:
>>
>> file=/etc/motd
>> OIFS=$IFS; IFS= # Change input field separator
>> while read -r line
>> do
>> echo "$line"
>> done < "$file"
>> IFS=$OIFS # Restore old value
>
>
> This doesn't restore the previous value if IFS was previously
> unset.
>
> Also note that commands in the loop have their stdin affected.
>
> As other pointed out:
>
> while IFS= read -r line <&3; do
> printf '%s\n' "$line" # echo should be banished
> done 3< "$file"
Let me translate for the newcomers:
while IFS= read -r line; do
echo "$line" # simple echo may remain
read dummy
done < "$file"
has the problem that the 2nd read command reads from the same file as
the loop's read.
Your trick with reading from &3 (or higher) prevents that.
This leads to the following solution to the FAQ
Why does rsh (or remsh) disturbe a "while read" loop?
rsh (or remsh) "steals" some characters from stdin.
Preferred solution:
while IFS= read -r line <&3; do
rsh remote-host "echo '$line'"
done 3< "$file"
The other solution is
while IFS= read -r line; do
rsh -n remote-host "echo '$line'"
done < "$file"
-- Michael Tosch @ hp : com
- Next message: Kenny McCormack: "Re: Usenet (Was: Re: CRON : Can you send values to CRON and get a result ?)"
- Previous message: matt_left_coast: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- In reply to: Stephane CHAZELAS: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Next in thread: Heiner Steven: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|