From mboxrd@z Thu Jan 1 00:00:00 1970 Message-Id: <11C11BC0-346A-4E77-9909-B87667FE6EF2@fastmail.fm> From: Ethan Grammatikidis To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> In-Reply-To: <79bfa351ebdb8906c17ec13976aa3e15@ladd.quanstro.net> Content-Type: multipart/mixed; boundary=Apple-Mail-30--49491776 Mime-Version: 1.0 (Apple Message framework v936) Date: Sat, 3 Apr 2010 18:24:44 +0100 References: <341DF8C2-A223-49A7-AA6C-65B7FB4C1CF5@fastmail.fm> <79bfa351ebdb8906c17ec13976aa3e15@ladd.quanstro.net> Subject: Re: [9fans] rc word splitting trouble Topicbox-Message-UUID: fc0840aa-ead5-11e9-9d60-3106f5b1d025 --Apple-Mail-30--49491776 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On 3 Apr 2010, at 15:38, erik quanstrom wrote: >> % fullloc = '/one/two?three+four' >> % params = `{echo $fullloc | sed -e 's;.*\?;;' -e 's;\+; ;g'} >> % for(param in $params) echo '
  • '$"param >>
  • three >>
  • four >> >> The 2nd and 3rd command lines are copied directly from the script, >> but >> the script itself outputs the following: >> >>
  • three four >> >> The sed expressions appear to be working correctly, to my eyes, so I >> don't understand what's going on. > > i suspect your ifs is set to something funky. > > inserting a "whatis params" in your script would be pretty > interesting. note that gnu sed will eat your regular expression > since you \? is their meta character. sed is p9p sed, verified with which, but ty. You're right about ifs, "whatis ifs" showed it up. It is set to newline-only for one line within the read loop, using the "var=foo command" syntax, but "command" in this case is another assignment. When I add a no-op command to the end (making it "assignment assignment command") rc complains "params: not found" and fails to run the loop properly. I don't know what kind of state the parser got into to produce that error. Anyway, I've fixed it for now by re-setting ifs after the line in question. I'm attaching the script; an embedded carriage-return makes a mess of both pasting the line here and posting it in a pastebin. The problem line is the first one in the while block. --Apple-Mail-30--49491776 Content-Disposition: attachment; filename=web-script.rc Content-Type: application/octet-stream; x-unix-mode=0644; name="web-script.rc" Content-Transfer-Encoding: quoted-printable #=20munch=20on=20request=0Areqlines=20=3D=20''=0Adone=20=3D=20false=0A= while(~=20$"done=20'false')=20{=0A=09ifs=20=3D=20'=0A'=20line=20=3D=20= `{read=20|sed=20's/=0D//g'}=0A=09#=20echo=20'^'$"line'$'=20>=20= /dev/stderr=0A=09reqlines=20=3D=20$"reqlines$"line'=0A'=0A=0A=09ifs=3D'=20= =09=0A'=0A=09if(echo=20$"line=20|=20grep=20'^GET=20'=20>=20/dev/null)=20= {=0A=09=09method=20=3D=20`{echo=20$"line=20|=20sed=20's;=20.*;;'}=0A=09=09= fullloc=20=3D=20`{echo=20$"line=20|=20sed=20-e=20's;[^=20]*=20/;/;'=20-e=20= 's;=20.*;;'}=0A=09=09location=20=3D=20`{echo=20$"fullloc=20|=20sed=20= 's;\?.*;;'}=0A=09=09params=20=3D=20`{echo=20$fullloc=20|=20sed=20-e=20= 's;.*\?;;'=20-e=20's;\+;=20;g'}=0A=09}=0A=0A=09if(~=20$"line=20'')=0A=09=09= done=20=3D=20true=0A}=0A=0A#=20spew=20our=20junk=0Aecho=20HTTP/1.0=20200=20= OK=0Aecho=20Content-type=20text/html=0Aecho=0A=0Acat=20<<=20EOF=0A=0A= =0AHello!=0A=0A=0A=0AEOF=0A=0Aecho=20= '

    Request=20received:=0A

    '=0Aecho=20-n=20$reqlines=0Aecho=20=
    '
    '=0A=0Aecho=20''=0A=0Aecho=20'
    '=0A=
    echo=20'%=20whatis=20ifs'=0Awhatis=20ifs=0Aecho=20'%=20whatis=20params'=0A=
    whatis=20params=0Aecho=20'%=20which=20sed'=0Awhich=20sed=0Aecho=20=
    '
    '=0A=0Aecho=20'=0A=0A=0A'=0A= --Apple-Mail-30--49491776 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit > > you can accomplish something that's equivalent in rc without > an explicit loop: > > echo '
  • ' ^ $params Good to know. I haven't used it here because the for loop generates nicer html from nicer source, if that makes sense. > > - erik > -- Simplicity does not precede complexity, but follows it. -- Alan Perlis --Apple-Mail-30--49491776--