rakitzis / rc

rc shell -- independent re-implementation for Unix of the Plan 9 shell (from circa 1992)
Other
250 stars 23 forks source link

Executing `flag n +` in a script does not stop execution. #93

Open borkovic opened 8 months ago

borkovic commented 8 months ago
rc/ $ cat s
ls trip*

flag n +
ls sig*.c

flag n -
ls glo*.c

Executing flag n + does not stop execution. If it did, how would we recover flag n -. Should flag 'n' be immutable?

rc/ $ rc -x s
ls trip.rc tripping.c
trip.rc     tripping.c
flag n +
ls sigmsgs.c signal.c
sigmsgs.c   signal.c
flag n -
ls glob.c glom.c
glob.c  glom.c

I expected no output, similar to the case when -n is passed on the command line:

rc/ $ rc -n -c 'ls trip*'
rc/ $
rc/ $ rc -x -n -c 'ls trip*'
ls trip*
rakitzis commented 8 months ago

Right, this is alluded to in the commit which added "flag". I have to say this is an unfortunate tangle at this point. I added -n mostly for testing purposes back in the day. "flag" was added much later. Perhaps it should simply reject "n" with an error. Resuming execution with "flag n -" makes no sense.

borkovic commented 7 months ago

Bash man page says set -n is ignored in interactive shells:

-n      Read commands but do not execute them.  This may be used to check a shell script for syntax errors.  This is ignored by interactive shells.

I agree with

Perhaps it should simply reject "n" with an error.