From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mack Wallace Content-Type: multipart/alternative; boundary="Apple-Mail=_93145BC2-FD63-4F53-909B-88A62C5E490F" Mime-Version: 1.0 (Mac OS X Mail 12.1 \(3445.101.1\)) Message-Id: <6A2B4894-94A0-430A-9A17-84A37F1B4BD6@mapinternet.com> Date: Sat, 5 Jan 2019 17:34:17 -0500 To: 9fans@9fans.net Subject: [9fans] How does one read a file line by line in an rc script? Topicbox-Message-UUID: f28f33f4-ead9-11e9-9d60-3106f5b1d025 --Apple-Mail=_93145BC2-FD63-4F53-909B-88A62C5E490F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Another, probably more stupid question - How does one read a text file = line by line in an rc script. In bash this works: #!/bin/bash =20 while read line =20 do =20 echo $line =20 done < $1=20 I=E2=80=99ve tried: #!/bin/rc =20 while (line=3D`{read $1}) =20 { echo $line =20 }=20 Which produces the first line of the file in an infinite loop. I=E2=80=99v= e tried the -m argument with no output. It=E2=80=99s probably simple, but just can=E2=80=99t seem to find the = equivalent. Regards, Mack --Apple-Mail=_93145BC2-FD63-4F53-909B-88A62C5E490F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Another, probably more stupid question - How does one read a = text file line by line in an rc script.

In bash this works:

#!/bin/bash  

while read line  
do  
echo $line  
done < $1 

I=E2=80=99ve tried:

#!/bin/rc  

while = (line=3D`{read $1})  
{
echo $line =  

Which produces the = first line of the file in an infinite loop. I=E2=80=99ve tried the -m = argument with no output.


It=E2=80=99s probably = simple, but just can=E2=80=99t seem to find the equivalent.

Regards,

Mack



= --Apple-Mail=_93145BC2-FD63-4F53-909B-88A62C5E490F-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Steve Simon Content-Type: multipart/alternative; boundary=Apple-Mail-F585AD8D-90A5-4D65-95F0-B1A7F171F185 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (1.0) Date: Sat, 5 Jan 2019 22:45:13 +0000 Message-Id: References: <6A2B4894-94A0-430A-9A17-84A37F1B4BD6@mapinternet.com> In-Reply-To: <6A2B4894-94A0-430A-9A17-84A37F1B4BD6@mapinternet.com> To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Subject: Re: [9fans] How does one read a file line by line in an rc script? Topicbox-Message-UUID: f295cc50-ead9-11e9-9d60-3106f5b1d025 --Apple-Mail-F585AD8D-90A5-4D65-95F0-B1A7F171F185 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable try cat $1 | while(line=3D`{read}){ echo $line } no doubt you cam do without the cat but i am unsure off hand where to put th= e redirect in and i am not on plan9 just now. -Steve > On 5 Jan 2019, at 10:34 pm, Mack Wallace wrote: >=20 > Another, probably more stupid question - How does one read a text file lin= e by line in an rc script. >=20 > In bash this works: >=20 > #!/bin/bash =20 >=20 > while read line =20 > do =20 > echo $line =20 > done < $1=20 >=20 > I=E2=80=99ve tried: >=20 > #!/bin/rc =20 >=20 > while (line=3D`{read $1}) =20 > { > echo $line =20 > }=20 >=20 > Which produces the first line of the file in an infinite loop. I=E2=80=99v= e tried the -m argument with no output. >=20 >=20 > It=E2=80=99s probably simple, but just can=E2=80=99t seem to find the equi= valent. >=20 > Regards, >=20 > Mack >=20 >=20 >=20 --Apple-Mail-F585AD8D-90A5-4D65-95F0-B1A7F171F185 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
try

cat $1 | while(line=3D`{read}){
echo $line
}
<= span style=3D"background-color: rgba(255, 255, 255, 0);">
no doubt you cam do without the cat but i am unsure off hand w= here to put the redirect in and i am not on plan9 just now.

-Steve

On 5 Jan 2= 019, at 10:34 pm, Mack Wallace <mackbw@mapinternet.com> wrote:

Another, probably more stupid question - How does one read a= text file line by line in an rc script.

In bash this works:

#!/bin/bash  

while read line  
do  
echo $line  
done < $1 

<= /div>
I=E2=80=99ve tried:

#!/bin/rc  

while (line=3D`{read $1})  {
echo $line  

Whi= ch produces the first line of the file in an infinite loop. I=E2=80=99ve tri= ed the -m argument with no output.


It=E2=80=99s probably s= imple, but just can=E2=80=99t seem to find the equivalent.

Regards,

Mack



=
= --Apple-Mail-F585AD8D-90A5-4D65-95F0-B1A7F171F185-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mack Wallace Content-Type: multipart/alternative; boundary="Apple-Mail=_642AA72A-A849-4D9B-BA3B-1682CED94216" Mime-Version: 1.0 (Mac OS X Mail 12.1 \(3445.101.1\)) Date: Sat, 5 Jan 2019 18:28:11 -0500 References: <6A2B4894-94A0-430A-9A17-84A37F1B4BD6@mapinternet.com> To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> In-Reply-To: Message-Id: Subject: Re: [9fans] How does one read a file line by line in an rc script? Topicbox-Message-UUID: f29efa0a-ead9-11e9-9d60-3106f5b1d025 --Apple-Mail=_642AA72A-A849-4D9B-BA3B-1682CED94216 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Thank you Steve. But unfortunately... That gives me =E2=80=9Crc (testread): variable name not singleton!=E2=80=9D= Trying the read with the -m option gets me the following errors repeated = over and over until I escape out. =E2=80=9Cawk i/o error occurred on /dev/stdin source line number 1 awk: i/o error occurred while closing /dev/stdin source line number 1"=20 =46rom the command line: cat testdata | read Gives me the first line of the file. cat testdata | read -m Puts all lines of the file to stdout. There was a sample script at the bottom of = http://doc.cat-v.org/plan_9/4th_edition/papers/rc = that I=E2=80=99ve = copied below. It creates its own read function. This is for getting text from stdin. = But I=E2=80=99m not seeing how it works - or if it is a path to get = where I want to go. I tried to copy that read function and put it at the = top of my script and the =E2=80=9Cwhile(read line) syntax below my other = work. When I ran the script it just waits for some input - after which, = it runs trough my other lines, not responding to my input file as $1 is = defined in the function, and then when it gets to the while, it prompts = me again. I tried to cat into the awk =E2=80=98{print; exit}=E2=80=99 in = the while structure - but that didn=E2=80=99t work either. hmmm=E2=80=A6. Mack t=3D/tmp/holmdel$pid fn read{ $1=3D=E2=80=98{awk =E2=80=99{print;exit}=E2=80=99} } ifs=3D=E2=80=99 =E2=80=99 # just a newline fn sigexit sigint sigquit sighup{ rm -f $t exit } cat <<=E2=80=99!=E2=80=99 >$t Allentown=20 ... Holmdel ... West Long Branch ! while(){ lab=3D=E2=80=98{fortune $t} echo $lab if(~ $lab Holmdel){ echo You lose. exit } while(read lab; ! grep -i -s $lab $t) echo No such location. if(~ $lab [hH]olmdel){ echo You win. exit } } > On Jan 5, 2019, at 5:45 PM, Steve Simon wrote: >=20 >=20 > try >=20 > cat $1 | while(line=3D`{read}){ > echo $line > } >=20 > no doubt you cam do without the cat but i am unsure off hand where to = put the redirect in and i am not on plan9 just now. >=20 > -Steve >=20 > On 5 Jan 2019, at 10:34 pm, Mack Wallace > wrote: >=20 >> Another, probably more stupid question - How does one read a text = file line by line in an rc script. >>=20 >> In bash this works: >>=20 >> #!/bin/bash =20 >>=20 >> while read line =20 >> do =20 >> echo $line =20 >> done < $1=20 >>=20 >> I=E2=80=99ve tried: >>=20 >> #!/bin/rc =20 >>=20 >> while (line=3D`{read $1}) =20 >> { >> echo $line =20 >> }=20 >>=20 >> Which produces the first line of the file in an infinite loop. I=E2=80=99= ve tried the -m argument with no output. >>=20 >>=20 >> It=E2=80=99s probably simple, but just can=E2=80=99t seem to find the = equivalent. >>=20 >> Regards, >>=20 >> Mack >>=20 >>=20 >>=20 --Apple-Mail=_642AA72A-A849-4D9B-BA3B-1682CED94216 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
Thank you Steve.

But = unfortunately...

That gives me =E2=80=9Crc (testread): variable name not = singleton!=E2=80=9D

Trying the read with the -m option gets me the following = errors repeated over and over until I escape out.
=E2=80=9Cawk i/o error occurred on /dev/stdin
 source line number 1
awk: i/o = error occurred while closing /dev/stdin
 source = line number 1" 

=46rom the command line:

cat testdata | read

Gives me the first line = of the file.

cat= testdata | read -m

Puts all lines of the file to stdout.

There was a sample script at the bottom = of http://doc.cat-v.org/plan_9/4th_edition/papers/rc that= I=E2=80=99ve copied below.

It creates its own read function. This is for getting text = from stdin. But I=E2=80=99m not seeing how it works - or if it is a path = to get where I want to go. I tried to copy that read function and put it = at the top of my script and the =E2=80=9Cwhile(read line) syntax below = my other work. When I ran the script it just waits for some input - = after which, it runs trough my other lines, not responding to my input = file as $1 is defined in the function, and then when it gets to the = while, it prompts me again. I tried to cat into the awk =E2=80=98{print; = exit}=E2=80=99 in the while structure - but that didn=E2=80=99t work = either.


hmmm=E2=80=A6.

Mack




t=3D/tmp/holmdel$pid

fn read{
    $1=3D=E2=80=98{awk =E2=80=99{print;exit}=E2=80=99= }
}

ifs=3D=E2=80=99
=E2=80=99  # just a newline

fn sigexit sigint sigquit sighup{
    = rm -f $t
    exit
}

cat <<=E2=80=99!=E2=80=99 >$t
Allentown 
...
Holmdel
...
West Long Branch
!

while(){
  =  lab=3D=E2=80=98{fortune $t}
   echo = $lab
   if(~ $lab Holmdel){
  =     echo You lose.
      exit
   }
   while(read lab; ! = grep -i -s $lab $t) echo No such location.
  =  if(~ $lab [hH]olmdel){
      echo You = win.
      exit
  =  }
}




On Jan 5, 2019, at 5:45 PM, Steve Simon = <steve@quintile.net> wrote:


try

cat $1 | while(line=3D`{read}){
echo = $line
}

no doubt you cam do = without the cat but i am unsure off hand where to put the redirect in = and i am not on plan9 just now.

-Steve

On 5 Jan 2019, at 10:34 pm, Mack Wallace = <mackbw@mapinternet.com> wrote:

Another, probably more stupid question - How = does one read a text file line by line in an rc script.
In bash this works:

#!/bin/bash  

while read line  
do  
echo $line  
done < $1 

I=E2=80=99ve tried:

#!/bin/rc  

while = (line=3D`{read $1})  
{
echo $line =  

Which produces the = first line of the file in an infinite loop. I=E2=80=99ve tried the -m = argument with no output.


It=E2=80=99s probably = simple, but just can=E2=80=99t seem to find the equivalent.

Regards,

Mack




= --Apple-Mail=_642AA72A-A849-4D9B-BA3B-1682CED94216-- From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: From: "Steve Simon" Date: Sat, 5 Jan 2019 23:46:59 +0000 To: 9fans@9fans.net In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [9fans] How does one read a file line by line in an rc script? Topicbox-Message-UUID: f2a6b272-ead9-11e9-9d60-3106f5b1d025 What are you running this on, is this byron's rc on unix? I just tried the secript I posted, cut and pasted into a tiny shell scropt called testread, and it just worked=E2=84=A2 maybe some other part of your script has a problem? My script below -----snip-----snip----- #!/bin/rc cat $1 | while(line=3D`{read}){ echo $line } -----snip-----snip----- Also, I didn't have the time to read all of your previous question, but I think what you are after is $"varname, this expands to the value of the variable but as a single argument, no matter if it, when it was assigned, had multiple, white space seperated words in it. for example: (NB: hugo% is my prompt) hugo% fred=3D(a b c d) hugo% echo $fred^-letter a-letter b-letter c-letter d-letter hugo% echo $"fred^-letter a b c d-letter -Steve From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sat, 5 Jan 2019 16:03:40 -0800 From: Anthony Martin To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Message-ID: <20190106000340.GB21088@alice> References: <6A2B4894-94A0-430A-9A17-84A37F1B4BD6@mapinternet.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6A2B4894-94A0-430A-9A17-84A37F1B4BD6@mapinternet.com> Subject: Re: [9fans] How does one read a file line by line in an rc script? Topicbox-Message-UUID: f2ae0fc2-ead9-11e9-9d60-3106f5b1d025 Mack Wallace once said: > Another, probably more stupid question - How does one read a text file > line by line in an rc script. You should really read the rc(1) man page. It will answer your questions. Here the functions foo and bar are equivalent: fn foo { <$1 while(l = `{read}) echo $l } fn bar { { while(l = `{read}) echo $l } <$1 } Think about why this one is not like the others: fn baz { while(l = `{read}){ echo $l } <$1 } Cheers, Anthony From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mack Wallace Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.1 \(3445.101.1\)) Date: Sat, 5 Jan 2019 19:33:50 -0500 References: To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> In-Reply-To: Message-Id: Subject: Re: [9fans] How does one read a file line by line in an rc script? Topicbox-Message-UUID: f2b1b744-ead9-11e9-9d60-3106f5b1d025 Thanks... I'm running Bell Labs Plan 9 in Virtualbox. (I=E2=80=99m not sure how to = get the version from the os or from rc) I copied and pasted the snip directly into a script with only that in it = - same error as before:=E2=80=9Crc (testread): variable name not = singleton!=E2=80=9D As for the second part - I will move that to the other thread. There are = now some things I=E2=80=99m exploring there with the ifs variable, = (which I thought the ifs variable was limited in plan 9 from what I = read).=20 Mack =20 > On Jan 5, 2019, at 6:46 PM, Steve Simon wrote: >=20 > What are you running this on, is this byron's rc on unix? >=20 > I just tried the secript I posted, cut and pasted into a > tiny shell scropt called testread, and it just worked=E2=84=A2 >=20 > maybe some other part of your script has a problem? >=20 > My script below > -----snip-----snip----- > #!/bin/rc >=20 > cat $1 | while(line=3D`{read}){ > echo $line > } >=20 > -----snip-----snip----- >=20 >=20 > Also, I didn't have the time to read all of your previous question, > but I think what you are after is $"varname, this expands to the value > of the variable but as a single argument, no matter if it, when > it was assigned, had multiple, white space seperated words in it. >=20 > for example: (NB: hugo% is my prompt) >=20 > hugo% fred=3D(a b c d) >=20 > hugo% echo $fred^-letter > a-letter b-letter c-letter d-letter >=20 > hugo% echo $"fred^-letter > a b c d-letter >=20 > -Steve >=20 >=20