rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re: -s flag
@ 1992-06-30 15:03 "D. Hugh Redelmeier"
  0 siblings, 0 replies; 9+ messages in thread
From: "D. Hugh Redelmeier" @ 1992-06-30 15:03 UTC (permalink / raw)
  To: dylan, davidf; +Cc: rc

| From: Matthew Farwell <dylan@ibmpcug.co.uk>
|
| It's a lot better to fix Jove than to 'fix' rc.  You could do this like
| vi/ex does it.  If I execute a subshell command in vi, then any % is
| replaced by the current filename, ie
|
| :!mv % %.bak

This is not better for a couple of reasons.

The first is that we are talking about an interractive shell, taking
over the tty for its command input.  For JOVE to do % replacement,
it would have to do the command input and feed the shell through a
PTY or something.  Ugh!

The second is that it would be yet another level of magic processing
of the command.  $1 already has a meaning to the shell, and the
shell can determine by its own rules (scope, quoting, etc.) when the
substitution is appropriate.

| From: "David J. Fiander" <golem!davidf>
|
| It would be nice if this feature was documented, though.

True.  I have just updated the JOVE documentation.

Hugh Redelmeier
hugh@mimosa.com or {utcsri, uunet!attcan, utzoo, scocan}!redvax!hugh
When all else fails: hugh@csri.toronto.edu
+1 416 482-8253


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

* Re: -s flag
@ 1992-07-02 14:03 Chet Ramey
  0 siblings, 0 replies; 9+ messages in thread
From: Chet Ramey @ 1992-07-02 14:03 UTC (permalink / raw)
  To: Gerry.Tomlinson; +Cc: rc

> ; rc  -c 'echo $*' one two
> one two
> ; ash -c 'echo $*' one two
> one two
> ; csh -c 'echo $*' one two
> one two
> ; ksh  -c 'echo $*' one two
> one two
> ; sh -c 'echo $*' one two
> two
> ; bash -c 'echo $*' one two
> 
> ;

This must be an old version of bash; my latest version gives

odin(2)$ ./bash -c 'echo $*' one two
one two

In any event, the standard seems to support the current rc
behavior.  I don't think you should worry about changing it.

Chet

--
``The use of history as therapy means the corruption of history as history.''
	-- Arthur Schlesinger

Chet Ramey, Case Western Reserve University	Internet: chet@po.CWRU.Edu


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

* Re: -s flag
  1992-07-01 21:30 "D. Hugh Redelmeier"
@ 1992-07-02 12:52 ` Gerry.Tomlinson
  0 siblings, 0 replies; 9+ messages in thread
From: Gerry.Tomlinson @ 1992-07-02 12:52 UTC (permalink / raw)
  To: rc

> 
> | respecting $SHELL so I can use all my rc functions. If instead I execed
> | $SHELL -s with the command line as stdin, with the filenames as the
> | arguments, and set the environment variable i to be that of the current
> | file, then one could reference all files with $*, numbered files with $n,
> | and the current file with $i, without xp having to touch the user's
> | input. Much nicer I think.
> 
> I suspect that you would be better off using -c.  It too allows
> passing parameters to the command.  That way you need not fool with
> stdin.
> 
yes, if all shells did the same with -c.
> As a matter of taste, I have misgivings about taking over $i.  It is
> a variable name that I frequently use in scripts.  That is the
> beauty of $1 etc.: those names were already reserved for this
> mechanism.  Of course, $current is a bit tiresome to type.
> 
being an X program I'd make the variable name a resource so you can
chose your own, but won't any clash only occur in functions which don't
redeclare the variable locally?

> Unfortunately, the positional parameters after -c or -s are not
> treated the same in different shells (at least under SunOS4.0.3):
> 
and it's different again on bash and I suspect other shells - on
On various machines I have access to I find:

; rc  -c 'echo $*' one two
one two
; ash -c 'echo $*' one two
one two
; csh -c 'echo $*' one two
one two
; ksh  -c 'echo $*' one two
one two
; sh -c 'echo $*' one two
two
; bash -c 'echo $*' one two

;

back to -s, 
matty@cs.su.OZ.AU mailed me the Plan 9 manual entry for rc:

> Invocation
>           If rc is started with no arguments it reads commands from
>           standard input.  Otherwise its first non-flag argument is
>           the name of a file from which to read commands (but see -c
>           below).  Subsequent arguments become the initial value of
>           $*.  Rc accepts the following command-line flags.
>           -c string  Commands are read from string.
>           -s         Print out exit status after any command where the
>                      status is non-null.
>           -e         Exit if $status is non-null after executing a
>                      simple command.
>           -i         If -i is present, or rc is given no arguments and
>                      its standard input is a terminal, it runs inter-
>                      actively.  Commands are prompted for using
>                      $prompt.
>           -I         Makes sure rc is not run interactively.
>           -l         If -l is given or the first character of argument
>                      zero is -, rc reads commands from
>                      $home/lib/profile, if it exists, before reading
> 
>      Page 8                       Plan 9              (printed 7/2/92)
> 
>      RC(1)                                                       RC(1)
> 
>                      its normal input.
>           -p         A no-op.
>           -d         A no-op.
>           -v         Echo input on file descriptor 2 as it is read.
>           -x         Print each simple command before executing it.
>                      -r Print debugging information (internal form of
>                      commands as they are executed).
>
> So, at least the version of rc we are using does not use the -s flag in
> the manner of recent discussion.  You can post this to the rc group if
> you feel people would be interested.
>
>					Matty.

seems like you can't win :-(,

	Gerry.

Gerry.Tomlinson@newcastle.ac.uk
Computing Laboratory, The University, Newcastle upon Tyne, UK, NE1 7RU
Tel: +44 091 222 8139


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

* Re: -s flag
@ 1992-07-01 21:30 "D. Hugh Redelmeier"
  1992-07-02 12:52 ` Gerry.Tomlinson
  0 siblings, 1 reply; 9+ messages in thread
From: "D. Hugh Redelmeier" @ 1992-07-01 21:30 UTC (permalink / raw)
  To: Gerry.Tomlinson, rc

| respecting $SHELL so I can use all my rc functions. If instead I execed
| $SHELL -s with the command line as stdin, with the filenames as the
| arguments, and set the environment variable i to be that of the current
| file, then one could reference all files with $*, numbered files with $n,
| and the current file with $i, without xp having to touch the user's
| input. Much nicer I think.

I suspect that you would be better off using -c.  It too allows
passing parameters to the command.  That way you need not fool with
stdin.

As a matter of taste, I have misgivings about taking over $i.  It is
a variable name that I frequently use in scripts.  That is the
beauty of $1 etc.: those names were already reserved for this
mechanism.  Of course, $current is a bit tiresome to type.

Unfortunately, the positional parameters after -c or -s are not
treated the same in different shells (at least under SunOS4.0.3):

	$ sh -c 'echo $*' one two
	two
	$ sh -c 'echo $0 $1' one two
	one two

	$ csh -c 'echo $*' one two
	one two
	$ csh -c 'echo $0 $1' one two
	No file for $0.

	$ rc -c 'echo $*' one two
	one two
	$ rc -c 'echo $0 $1' one two
	rc one
[This is an old version of rc; it may have changed.]

	$ sh -si one two
	$ echo $*
	one two
	$ echo $0 $1
	sh one
	$ exit

	$ csh -si one two
	redvax% echo $*
	one two
	redvax% echo $0 $1
	No file for $0.
	redvax% exit

	$ rc -si one two
	rc: illegal option -- s
	$ rc -i one two
	one: No such file or directory

For portability reasons, I only promise to set $1, and I do so by
passing two copies of the string as positional parameters.

Hugh Redelmeier
hugh@mimosa.com or {utcsri, uunet!attcan, utzoo, scocan}!redvax!hugh
When all else fails: hugh@csri.toronto.edu
+1 416 482-8253


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

* Re: -s flag
  1992-07-01 12:52 ` Gerry.Tomlinson
@ 1992-07-01 21:14   ` Chris Siebenmann
  0 siblings, 0 replies; 9+ messages in thread
From: Chris Siebenmann @ 1992-07-01 21:14 UTC (permalink / raw)
  To: rc

 Duff's rc doesn't seem to have a -s flag, at least not one that means
what it means to sh and csh.

	- cks


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

* Re: -s flag
  1992-06-30 15:29 haahr
@ 1992-07-01 12:52 ` Gerry.Tomlinson
  1992-07-01 21:14   ` Chris Siebenmann
  0 siblings, 1 reply; 9+ messages in thread
From: Gerry.Tomlinson @ 1992-07-01 12:52 UTC (permalink / raw)
  To: rc

> 
> > It's a lot better to fix Jove than to 'fix' rc.  You could do this like
> > vi/ex does it.  If I execute a subshell command in vi, then any % is
> > replaced by the current filename, ie
> > 	:!mv % %.bak
> > would be expanded to
> > 	:!mv foo foo.bak
> > etc.  This is a lot better than hacking a kludge into rc for the sake of
> > one editor.
> 
> i disagree vehemently.  shell variable subsitution is a much better defined
> mechanism than vi's subtituting for %.  (e.g., how do you quote %?  what if
> you invoked vi without a filename?)  in general, i take issue with any
> program blindly editing input that the user has typed for another program,
> even if that other program is a shell.
> 
> now, one could make the argument that the file should be stored in an
> environment variable, e.g. $file, and if every editor were coerced to
> use rc's notion of control-a separated lists, that would even work for
> multiple files.  but $n is a logical place to put the file names, and
> has no other conventional meaning for subshells invoked from editors.
> 

I've been thinking how to reference filenames from  shell escapes in my
X file display program xp (export.lcs.mit.edu:contrib/xp-1.1.tar.Z). I
originally adopted the vi % mechanism, simply  using system or popen to
execute the command after expanding any %'s, however I was never very
happy with this 'cos of the quoting problem & the lack of
generalisation. My development version does its own "system" thereby
respecting $SHELL so I can use all my rc functions. If instead I execed
$SHELL -s with the command line as stdin, with the filenames as the
arguments, and set the environment variable i to be that of the current
file, then one could reference all files with $*, numbered files with $n,
and the current file with $i, without xp having to touch the user's
input. Much nicer I think.

Until this discussion started I wasn't even aware of the -s option.
When did it first appear? I have a V8 manual to hand and it's
in there - does anyone know if it's in Tom Duff's rc?

	Gerry.

Gerry.Tomlinson@newcastle.ac.uk
Computing Laboratory, The University, Newcastle upon Tyne, UK, NE1 7RU
Tel: +44 091 222 8139




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

* Re: -s flag
@ 1992-06-30 15:29 haahr
  1992-07-01 12:52 ` Gerry.Tomlinson
  0 siblings, 1 reply; 9+ messages in thread
From: haahr @ 1992-06-30 15:29 UTC (permalink / raw)
  To: dylan; +Cc: rc

> It's a lot better to fix Jove than to 'fix' rc.  You could do this like
> vi/ex does it.  If I execute a subshell command in vi, then any % is
> replaced by the current filename, ie
> 	:!mv % %.bak
> would be expanded to
> 	:!mv foo foo.bak
> etc.  This is a lot better than hacking a kludge into rc for the sake of
> one editor.

i disagree vehemently.  shell variable subsitution is a much better defined
mechanism than vi's subtituting for %.  (e.g., how do you quote %?  what if
you invoked vi without a filename?)  in general, i take issue with any
program blindly editing input that the user has typed for another program,
even if that other program is a shell.

now, one could make the argument that the file should be stored in an
environment variable, e.g. $file, and if every editor were coerced to
use rc's notion of control-a separated lists, that would even work for
multiple files.  but $n is a logical place to put the file names, and
has no other conventional meaning for subshells invoked from editors.

even before Hugh posted his explaination on why jove does what it does,
i tended to agree with John that rc should support -s with the same meaning
as sh's -s, because it has evolved as a convention among shells, part of
the standard options set, like -c and -e.  now i'm convinced.

paul


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

* Re: -s flag
  1992-06-30  6:55 "D. Hugh Redelmeier"
@ 1992-06-30  8:26 ` Matthew Farwell
  0 siblings, 0 replies; 9+ messages in thread
From: Matthew Farwell @ 1992-06-30  8:26 UTC (permalink / raw)
  To: hugh; +Cc: rc

In article <9206300655.AA09921@redvax.mimosa.com> you write:
>| From: John (_You_ hide, they seek.) Mackin <john@vetsci.su.oz.au>
>|  Hey, can anyone on the list tell us
>| all if they have any reason at all for wanting -s?  Inquiring minds
>| want to know.
>|
>| ... I will always be willing to entertain rc features
>| that keep it compatible (in appropriate ways) with traditional shells.
>
>| From: Bob Gibson <rjg@sco.com>
>|
>| My editor, jove, starts up subshells with the -s option, and obviously
>| fails to do so if the shell doesn't support it.  In this case, the
>| correct thing to do would be to fix jove to make this configurable.
>
>I am the person who made JOVE invoke subshells with the -s flag.  I
>did it in about 1984, so I have forgotten some of the subtle
>details.  I will try to reconstruct them.
>
>First, a hint from SunOS 4.0.3 sh(1):
>
>     -s             If the -s option is present or  if  no  argu-
>                    ments remain commands are read from the stan-
>                    dard input.  Any remaining arguments  specify
>                    the   positional  parameters.   Shell  output
>                    (except for Special Commands) is  written  to
>                    file descriptor 2.
>
>Actually, the story goes back to about about 1976, when I was
>hacking on ed(1).  I changed the ! command so that the shell command
>was invoked in such a way that the current file could be referred to
>as $1.  This was extremely convenient.
>	!cp -p $1 $1.BAK
>	!chmod u+w $1
>	!pr $1 | lpr
>	!diff $1.BAK $1
>
>When I started hacking on JOVE, I naturally wanted this feature
>too.  The only way that I could get it to work with csh and and all
>versions of sh was to throw in the -s.  [I don't remember which
>failed without the -s]
>
>I want to keep using this feature.  I don't want to hack JOVE to
>allow the suppression of the -s for rc.  I think it is better to
>hack rc to accept -s like other UNIX shells.

It's a lot better to fix Jove than to 'fix' rc.  You could do this like
vi/ex does it.  If I execute a subshell command in vi, then any % is
replaced by the current filename, ie

:!mv % %.bak

would be expanded to 

:!mv foo foo.bak

etc.  This is a lot better than hacking a kludge into rc for the sake of
one editor.

Dylan.

-- 
It is no coincidence that in no known language does the phrase 'As
pretty as an Airport' appear -- Douglas Adams


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

* -s flag
@ 1992-06-30  6:55 "D. Hugh Redelmeier"
  1992-06-30  8:26 ` Matthew Farwell
  0 siblings, 1 reply; 9+ messages in thread
From: "D. Hugh Redelmeier" @ 1992-06-30  6:55 UTC (permalink / raw)
  To: rc

| From: John (_You_ hide, they seek.) Mackin <john@vetsci.su.oz.au>
|
|  Hey, can anyone on the list tell us
| all if they have any reason at all for wanting -s?  Inquiring minds
| want to know.
|
| ... I will always be willing to entertain rc features
| that keep it compatible (in appropriate ways) with traditional shells.

| From: Bob Gibson <rjg@sco.com>
|
| My editor, jove, starts up subshells with the -s option, and obviously
| fails to do so if the shell doesn't support it.  In this case, the
| correct thing to do would be to fix jove to make this configurable.

I am the person who made JOVE invoke subshells with the -s flag.  I
did it in about 1984, so I have forgotten some of the subtle
details.  I will try to reconstruct them.

First, a hint from SunOS 4.0.3 sh(1):

     -s             If the -s option is present or  if  no  argu-
                    ments remain commands are read from the stan-
                    dard input.  Any remaining arguments  specify
                    the   positional  parameters.   Shell  output
                    (except for Special Commands) is  written  to
                    file descriptor 2.

Actually, the story goes back to about about 1976, when I was
hacking on ed(1).  I changed the ! command so that the shell command
was invoked in such a way that the current file could be referred to
as $1.  This was extremely convenient.
	!cp -p $1 $1.BAK
	!chmod u+w $1
	!pr $1 | lpr
	!diff $1.BAK $1

When I started hacking on JOVE, I naturally wanted this feature
too.  The only way that I could get it to work with csh and and all
versions of sh was to throw in the -s.  [I don't remember which
failed without the -s]

I want to keep using this feature.  I don't want to hack JOVE to
allow the suppression of the -s for rc.  I think it is better to
hack rc to accept -s like other UNIX shells.

Hugh Redelmeier
hugh@mimosa.com or {utcsri, uunet!attcan, utzoo, scocan}!redvax!hugh
When all else fails: hugh@csri.toronto.edu
+1 416 482-8253


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

end of thread, other threads:[~1992-07-02 14:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-06-30 15:03 -s flag "D. Hugh Redelmeier"
  -- strict thread matches above, loose matches on Subject: below --
1992-07-02 14:03 Chet Ramey
1992-07-01 21:30 "D. Hugh Redelmeier"
1992-07-02 12:52 ` Gerry.Tomlinson
1992-06-30 15:29 haahr
1992-07-01 12:52 ` Gerry.Tomlinson
1992-07-01 21:14   ` Chris Siebenmann
1992-06-30  6:55 "D. Hugh Redelmeier"
1992-06-30  8:26 ` Matthew Farwell

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