[clug] Please help
Kim Holburn
kim.holburn at anu.edu.au
Tue Jun 1 09:39:26 GMT 2004
On 2004 Jun 1, , at 6:50 PM, Stephen Jenkin wrote:
>
> On Tue, 1 Jun 2004, Martin Pool wrote:
>
>> On 1 Jun 2004, "Crosskey, Jason (DPS)" <Jason.Crosskey at aph.gov.au>
>> wrote:
>>> I can't get this script to work in bash, see bleow, but it works in
>>> ksh.
>>> Variables get lost after the while loop is done in bash which causes
>>> the
>>> problem, but I don't know how to fix it.
>>>
>>> hostfile=/etc/hosts
>>>
>>> echo "This program will find a host name in $hostfile"
>>> echo "Enter an IP address:" ;read findIP
>>>
>>> while test "$findIP" != 999
>>> do
>>> cat $hostfile | while read line
>>
>> maybe
>>
>> while read line < $hostfile
>
> I tried this first off. 'bash' barfs on it, v. strange.
>
> An alternative works:
> exec 3< $hostfile
> while read -u3 line
count =0;
while read line; do
echo "line:$count:($line)"
count=$(($count + 1))
done < /etc/hosts
or on one line:
count =0;while read line; do echo "line:$count:($line)";
count=$(($count + 1)); done < /etc/hosts
>
>>
>>
>> --
>> Martin
>>
>
>
>
> Steve Jenkin, Unix Sys Admin
> 0412 786 915 (+61 412 786 915)
> PO Box 48, Kippax ACT 2615, AUSTRALIA
>
>
>
--
Kim Holburn
IT Manager, Canberra Research Laboratory
National Information and Communication Technology Australia
Ph: +61 2 61258620 M: +61 0417820641
Email: kim.holburn at anu.edu.au - PGP Public Key on request
Democracy imposed from without is the severest form of tyranny.
-- Lloyd Biggle, Jr. Analog, Apr 1961
More information about the linux
mailing list