9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] problem with a here document in rc
@ 2013-05-02 13:22 Rudolf Sykora
  2013-05-02 15:24 ` erik quanstrom
  0 siblings, 1 reply; 9+ messages in thread
From: Rudolf Sykora @ 2013-05-02 13:22 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

I have a problem with writing correctly a here document in rc.
I wrote, say:

s = (1 2)
for(i in $s) {
	mkdir -p $i
	cp POSCAR $i
	@{
		cd $i
		ed POSCAR <<EOF >[2]/dev/null
	}
}
2c
$i
.
w
q
EOF

and I wanted to have the 2nd line of individual POSCAR files replaced
with the immediate value of $i.
But the script doesn't do it, and I don't know if it can be modified
in a simple way so that it did.
(I could possibly use sed [ie. without a here document] but ...)

If anyone can tell me...
Thanks!
Ruda



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] problem with a here document in rc
  2013-05-02 13:22 [9fans] problem with a here document in rc Rudolf Sykora
@ 2013-05-02 15:24 ` erik quanstrom
  2013-05-02 15:48   ` Rudolf Sykora
  0 siblings, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2013-05-02 15:24 UTC (permalink / raw)
  To: 9fans

> s = (1 2)
> for(i in $s) {
> 	mkdir -p $i
> 	cp POSCAR $i
> 	@{
> 		cd $i
> 		ed POSCAR <<EOF >[2]/dev/null
> 	}
> }
> 2c
> $i
> .
> w
> q

i usually solve this problem like this

	for(i in 1 2){
		mkdir -p $i || fatal
		cp POSCAR $i || fatal
		@{
			{
				echo 2c
				echo $i
				echo .
				echo w
				echo q
			} | ed POSCAR
		}
	}

- erik



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] problem with a here document in rc
  2013-05-02 15:24 ` erik quanstrom
@ 2013-05-02 15:48   ` Rudolf Sykora
  2013-05-06  7:27     ` Rudolf Sykora
  0 siblings, 1 reply; 9+ messages in thread
From: Rudolf Sykora @ 2013-05-02 15:48 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 2 May 2013 17:24, erik quanstrom <quanstro@quanstro.net> wrote:
> i usually solve this problem like this
>
>         for(i in 1 2){
>                 mkdir -p $i || fatal
>                 cp POSCAR $i || fatal
>                 @{
>                         {
>                                 echo 2c
>                                 echo $i
>                                 echo .
>                                 echo w
>                                 echo q
>                         } | ed POSCAR
>                 }
>         }
>
> - erik


So you avoid a here document...
Then, is it so that a here document can't ever serve the purpose (ie.
it is limited in the way that any present variables are evaluated just
once; when then?)?

Thanks for a clarification!
Ruda



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] problem with a here document in rc
  2013-05-02 15:48   ` Rudolf Sykora
@ 2013-05-06  7:27     ` Rudolf Sykora
  2013-05-06 13:37       ` erik quanstrom
  2013-05-07 20:40       ` Martin Kühl
  0 siblings, 2 replies; 9+ messages in thread
From: Rudolf Sykora @ 2013-05-06  7:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

so I repeat my question. While this is possible in bash:

;cat aBash
for i in 1 2 3
do
cat <<!
$i
!
done
;
;bash aBash
1
2
3
;

it doesn't work in rc:

;cat aRc
for(i in 1 2 3) {
	cat <<!
}
$i
!
;
;rc aRc



;

Is this as it should be?
Can the rc example be modified --- still using a here document --- so
that it works?

Thanks
Ruda



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] problem with a here document in rc
  2013-05-06  7:27     ` Rudolf Sykora
@ 2013-05-06 13:37       ` erik quanstrom
  2013-05-07 20:40       ` Martin Kühl
  1 sibling, 0 replies; 9+ messages in thread
From: erik quanstrom @ 2013-05-06 13:37 UTC (permalink / raw)
  To: 9fans

> Can the rc example be modified --- still using a here document --- so
> that it works?

no.

- erik



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] problem with a here document in rc
  2013-05-06  7:27     ` Rudolf Sykora
  2013-05-06 13:37       ` erik quanstrom
@ 2013-05-07 20:40       ` Martin Kühl
  2013-05-07 22:08         ` erik quanstrom
  1 sibling, 1 reply; 9+ messages in thread
From: Martin Kühl @ 2013-05-07 20:40 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Mon, May 6, 2013 at 9:27 AM, Rudolf Sykora <rudolf.sykora@gmail.com> wrote:
> Can the rc example be modified --- still using a here document --- so
> that it works?

I guess I must be missing something, but this seems equivalent to your
bash script:

for(i in 1 2 3) {
        cat <<!
$i
!
}



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] problem with a here document in rc
  2013-05-07 20:40       ` Martin Kühl
@ 2013-05-07 22:08         ` erik quanstrom
  2013-05-08  2:53           ` Martin Kühl
  0 siblings, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2013-05-07 22:08 UTC (permalink / raw)
  To: 9fans

> I guess I must be missing something, but this seems equivalent to your
> bash script:
>
> for(i in 1 2 3) {
>         cat <<!
> $i
> !
> }

clearly you did not run this script.  this doesn't
work for the same reason that here docs in functions
don't work.

- erik



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] problem with a here document in rc
  2013-05-07 22:08         ` erik quanstrom
@ 2013-05-08  2:53           ` Martin Kühl
  2013-05-08  3:02             ` erik quanstrom
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Kühl @ 2013-05-08  2:53 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Wed, May 8, 2013 at 12:08 AM, erik quanstrom <quanstro@quanstro.net> wrote:
>> I guess I must be missing something, but this seems equivalent to your
>> bash script:
>>
>> for(i in 1 2 3) {
>>         cat <<!
>> $i
>> !
>> }
>
> clearly you did not run this script.  this doesn't
> work for the same reason that here docs in functions
> don't work.

I actually did, but accidentally ran the old unix port. sorry for the noise.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] problem with a here document in rc
  2013-05-08  2:53           ` Martin Kühl
@ 2013-05-08  3:02             ` erik quanstrom
  0 siblings, 0 replies; 9+ messages in thread
From: erik quanstrom @ 2013-05-08  3:02 UTC (permalink / raw)
  To: 9fans

> > clearly you did not run this script.  this doesn't
> > work for the same reason that here docs in functions
> > don't work.
>
> I actually did, but accidentally ran the old unix port. sorry for the noise.

ah, yes  byron did make here documents work, and i think paul
goaded him into adding here strings with three <s.  but that was years ago.

it's not clear to me that there's any current point in a here doc.
sure you can save a bit of memory, but i don't remember
the last boddle i unpacked.  and regardless, i'm sure it would have
fit easily into memory.

- erik



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-05-08  3:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-02 13:22 [9fans] problem with a here document in rc Rudolf Sykora
2013-05-02 15:24 ` erik quanstrom
2013-05-02 15:48   ` Rudolf Sykora
2013-05-06  7:27     ` Rudolf Sykora
2013-05-06 13:37       ` erik quanstrom
2013-05-07 20:40       ` Martin Kühl
2013-05-07 22:08         ` erik quanstrom
2013-05-08  2:53           ` Martin Kühl
2013-05-08  3:02             ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).