Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[9fans] problem with a here document in rc

20 views
Skip to first unread message

Rudolf Sykora

unread,
May 2, 2013, 9:22:58 AM5/2/13
to
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

erik quanstrom

unread,
May 2, 2013, 11:24:27 AM5/2/13
to
> 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

Rudolf Sykora

unread,
May 2, 2013, 11:48:03 AM5/2/13
to
On 2 May 2013 17:24, erik quanstrom <quan...@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

Rudolf Sykora

unread,
May 6, 2013, 3:27:31 AM5/6/13
to
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

erik quanstrom

unread,
May 6, 2013, 9:37:58 AM5/6/13
to
> Can the rc example be modified --- still using a here document --- so
> that it works?

no.

- erik

Martin Kühl

unread,
May 7, 2013, 4:40:18 PM5/7/13
to
On Mon, May 6, 2013 at 9:27 AM, Rudolf Sykora <rudolf...@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:

erik quanstrom

unread,
May 7, 2013, 6:08:31 PM5/7/13
to
> 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

erik quanstrom

unread,
May 7, 2013, 11:02:40 PM5/7/13
to
> > 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

Martin Kühl

unread,
May 7, 2013, 10:53:59 PM5/7/13
to
0 new messages