[comp.bugs.4bsd] vi with an 8-bit shell

simon@lfcs.ed.ac.uk (Simon Brown) (07/27/88)

If you use '%' or '#'in a shell-escape, such as
	:!diff % %.orig
then vi will set the high-bit on the substituted filenames. If you use a
shell which passes 8-bit data correctly (such as ksh-i), then you get:
	diff: mumble.c:  Invalid argument
This doesn't happen for sh or csh, of course, since they strip 8-bit data.

See the unix0() function in ex_unix.c.


	Simon.

| Simon Brown                                    | UUCP: mcvax!ukc!lfcs!simon
| Laboratory for Foundations of Computer Science | ARPA: simon%lfcs.ed
| Department of Computer Science                 |            @nss.cs.ucl.uk
| University of Edinburgh, Scotland, UK.         | JANET: simon@uk.ac.ed.lfcs

greim@sbsvax.UUCP (Michael Greim) (07/29/88)

In article <571@etive.ed.ac.uk>, simon@lfcs.ed.ac.uk (Simon Brown) writes:
< If you use '%' or '#'in a shell-escape, such as
< 	:!diff % %.orig
< then vi will set the high-bit on the substituted filenames. If you use a
< shell which passes 8-bit data correctly (such as ksh-i), then you get:
< 	diff: mumble.c:  Invalid argument
< This doesn't happen for sh or csh, of course, since they strip 8-bit data.
< 
< See the unix0() function in ex_unix.c.
< 
< 
< 	Simon.
Yes, it's there. Probably it's for filenames which contain shell
meta characters like "*" or just plain spaces. By quoting vi ensures that
the filename is "correctly" interpreted by the shell. Most people, like
me, never notice such a thing, because they have plain sh or csh.
I think when vi was written, there was no such thing as a "8 bit" shell.
Can you come up with a fix ?

	-mg
-- 
+------------------------------------------------------------------------------+
| UUCP:  ...!uunet!unido!sbsvax!greim   | Michael T. Greim                     |
|        or greim@sbsvax.UUCP           | Universitaet des Saarlandes          |
| CSNET: greim%sbsvax.uucp@Germany.CSnet| FB 10 - Informatik (Dept. of CS)     |
| ARPA:  greim%sbsvax.uucp@uunet.UU.NET | Bau 36, Im Stadtwald 15              |
| Phone: +49 681 302 2434               | D-6600 Saarbruecken 11, West Germany |
+------------------------------------------------------------------------------+
| # include <disclaimers/std.h>                                                |
+------------------------------------------------------------------------------+

simon@lfcs.ed.ac.uk (Simon Brown) (07/31/88)

In article <575@sbsvax.UUCP> greim@sbsvax.UUCP (Michael Greim) writes:
>In article <571@etive.ed.ac.uk>, simon@lfcs.ed.ac.uk (Simon Brown) writes:
>< If you use '%' or '#'in a shell-escape, such as
>< 	:!diff % %.orig
>< then vi will set the high-bit on the substituted filenames. If you use a
>< shell which passes 8-bit data correctly (such as ksh-i), then you get:
>< 	diff: mumble.c:  Invalid argument
>< This doesn't happen for sh or csh, of course, since they strip 8-bit data.
>< 
>< See the unix0() function in ex_unix.c.
>< 

>Yes, it's there. Probably it's for filenames which contain shell
>meta characters like "*" or just plain spaces. By quoting vi ensures that
>the filename is "correctly" interpreted by the shell. Most people, like
>me, never notice such a thing, because they have plain sh or csh.
>I think when vi was written, there was no such thing as a "8 bit" shell.
>Can you come up with a fix ?

well, just changing the "case '%'" switch-field in unix0() so it uses
	*up++ = *fp++
in place of
	*up++ = *fp++ | QUOTE;
seems to do the trick. (i naughtily patched the binary instead of changing
the source, but that was just to quickily check it out :-).

of course, it means you have to explicitly quote it if the filename contains 
shell meta-chars, but that's not too much of a hardship...

	
	Simon.

| Simon Brown                                    | UUCP: mcvax!ukc!lfcs!simon
| Laboratory for Foundations of Computer Science | ARPA: simon%lfcs.ed
| Department of Computer Science                 |          @nss.cs.ucl.ac.uk
| University of Edinburgh, Scotland, UK.         | JANET: simon@uk.ac.ed.lfcs

greim@sbsvax.UUCP (Michael Greim) (08/02/88)

In article <594@etive.ed.ac.uk>, simon@lfcs.ed.ac.uk (Simon Brown) writes:
> 
> well, just changing the "case '%'" switch-field in unix0() so it uses
> 	*up++ = *fp++
> in place of
> 	*up++ = *fp++ | QUOTE;
> seems to do the trick. (i naughtily patched the binary instead of changing
> the source, but that was just to quickily check it out :-).
That was obvious, of course. What I meant was : "whatever is this
QUOTE for?", and "will removing it break anything?".
I hazarded a guess that it might be to protect shell meta
characters, but this might be completely wrong. Just now I don't have the
time (and the nerves) to dig into vi to find out.
I will leave the QUOTE in, because we have no ksh, so it does not matter for
us.

	-mg
-- 
+------------------------------------------------------------------------------+
| UUCP:  ...!uunet!unido!sbsvax!greim   | Michael T. Greim                     |
|        or greim@sbsvax.UUCP           | Universitaet des Saarlandes          |
| CSNET: greim%sbsvax.uucp@Germany.CSnet| FB 10 - Informatik (Dept. of CS)     |
| ARPA:  greim%sbsvax.uucp@uunet.UU.NET | Bau 36, Im Stadtwald 15              |
| Phone: +49 681 302 2434               | D-6600 Saarbruecken 11, West Germany |
+------------------------------------------------------------------------------+
| # include <disclaimers/std.h>                                                |
+------------------------------------------------------------------------------+

karl@haddock.ISC.COM (Karl Heuer) (08/03/88)

In article <580@sbsvax.UUCP> greim@sbsvax.UUCP (Michael Greim) writes:
>>	*up++ = *fp++ | QUOTE;
>That was obvious, of course. What I meant was : "whatever is this
>QUOTE for?", and "will removing it break anything?".

Yes, the QUOTE is there for protecting shell metacharacters.  No, it won't
break anything else.  I recommend that you fix it now, even if you don't have
an 8-bit shell, because it'll save you time and agony later when you do.