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