vi can't handle ":! cmd %"

Nick Crossley ndjc at hobbit.UUCP
Thu Nov 29 06:15:47 AEST 1990


In article <1990Nov27.210425.25747 at cbnewsj.att.com> btwomey at cbnewsj.att.com (william.tw0mey) writes:
>I'm running System V, R3.2.3 and ksh88d. While in vi editing
>foo.c, with shell=/bin/ksh, if I try
>:! cc %
>I get a message to the effect that cc can't access foo.c.
>Now the interesting part is if I try
>:!echo % | od -c
>I get
>0000000   f   o   o   .   c  \n
>	346 357 357 256 343 012
>0000006
>which is the characters for "foo.c" but with the high order bits set.
>What flags have to be redefined for vi to pass the filename to 
>the shell with the high order bits unset?

The problem is that you are using an 8-bit clean version of ksh,
with a partially 7-bit version of vi/ex.

Older shells (csh and sh) used to (and in many versions still do) set the
top bit of characters internally as a quoting mechanism.  vi, somewhat
rashly, uses this knowledge to quote the expansion of % and # filenames
automatically, as if you had written '%' or '#'.  Of course, when 8-bit
clean shells such as recent versions of ksh appear, this behaviour of vi
is broken, since such shells just accept the top bit as is.

A fix is to change vi so that it does not attempt to 'quote' % and #
filenames.  If you are editing files with funny names, you might have
to use explicit quotes around % or # in shell escapes; this seems
eminently more reasonable to me than the 8-bit hack.  An alternative
would be to make vi actually put in \ and/or ' characters, but it seems
hardly worth the effort.

In Unix V.4, the quoting has been removed.

Below is a patch to BSD and SysV[123] vi/ex to remove the 8-bit quoting.
Your line numbers may vary depending on the version of vi, and because
we have some source control info at the top of the files.


*** port/ex_unix.c.old
--- port/ex_unix.c
***************
*** 77,83 ****
  			while (*fp) {
  				if (up >= &uxb[UXBSIZE])
  					goto tunix;
! 				*up++ = *fp++ | QUOTE;
  			}
  			break;
  		}
--- 77,83 ----
  			while (*fp) {
  				if (up >= &uxb[UXBSIZE])
  					goto tunix;
! 				*up++ = *fp++;
  			}
  			break;
  		}

-- 

<<< standard disclaimers >>>
Nick Crossley, ICL NA, 9801 Muirlands, Irvine, CA 92718-2521, USA 714-458-7282
uunet!ccicpg!ndjc  /  ndjc at ccicpg.UUCP



More information about the Comp.unix.misc mailing list