9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] rc eflag bug?
@ 2005-06-24 20:28 Sam
  2005-06-29  9:02 ` Richard Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Sam @ 2005-06-24 20:28 UTC (permalink / raw)
  To: 9fans

Specifically:

baron% @{
 	flag e +
 	flag e; echo eflag: $status
 	echo one
 	cp /this/should /bail
 	echo time
 	}
eflag:
one
cp: can't stat /this/should: '/this/should' directory entry not found
time
baron% rc; echo back
baron% c=c
baron% if(~ $c c){
 	flag e +
 	echo two
 	cp /this/should /bail
 	echo times
 	}
two
cp: can't stat /this/should: '/this/should' directory entry not found
times
baron% #and yet when run again ...
baron% if(~ $c c){
 	echo three
 	cp /this/will /bail
 	echo times
 	}
three
cp: can't stat /this/will: '/this/will' directory entry not found
back
baron%

Sam



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

* Re: [9fans] rc eflag bug?
  2005-06-24 20:28 [9fans] rc eflag bug? Sam
@ 2005-06-29  9:02 ` Richard Miller
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Miller @ 2005-06-29  9:02 UTC (permalink / raw)
  To: 9fans

Here's an explanation for this surprising rc behaviour:

> baron% c=c
> baron% if(~ $c c){
>  	flag e +
>  	echo two
>  	cp /this/should /bail
>  	echo times
>  	}
> two
> cp: can't stat /this/should: '/this/should' directory entry not found
> times
> baron% #and yet when run again ...
> baron% if(~ $c c){
>  	echo three
>  	cp /this/will /bail
>  	echo times
>  	}
> three
> cp: can't stat /this/will: '/this/will' directory entry not found
> back
> baron%

Each top-level (simple or compound) rc command is compiled into threaded code
and then executed.  If the 'e' flag is set at compile time, rc emits code after
each simple command to check the status and exit if non-null.  So if the flag
becomes set during the execution of a compound command, it doesn't take effect
until that compound command finishes and the next command is compiled.  If the
compound command was in a subshell (using @{...}), the 'e' flag setting won't
affect the parent shell so it has no effect.  (I'm ignoring the special case
of the 'eval' command ...)

So, is it a bug, or a documentation change to explain that changes to the 'e'
flag take effect from the next top-level command?

-- Richard



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

end of thread, other threads:[~2005-06-29  9:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-24 20:28 [9fans] rc eflag bug? Sam
2005-06-29  9:02 ` Richard Miller

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).