/bin/sh variable substitution

John Bruner jdb at mordor.UUCP
Sat Jun 30 05:44:50 AEST 1984


I noticed recently that the (Bourne) shell's ${X=y} construction
does not have the behavior that I expected.  It appears that when
a variable is assigned a quoted value, for example:

	${XYZZY="plugh"}  <or>	${XYZZY='plugh'}

that every character of the quoted value is stored with the 0200
bit on.  Normally this has no visible effect because the shell
strips the eighth bit (along with  non-printable characters) after
variable substitution when it evaluates a command.  However, this
is not the case for "<<" I/O redirection: the variables are passed
unfiltered.  For instance, in the following case:

	cat > plover <<!EOF!
	${XYZZY="plugh"}
	!EOF!

the file "plover" will contain "\360\354\365\347\350\n"

I also observed this behavior with the ${X-y} construction.  The
0200 bits are not set if the string is unquoted: ${XYZZY=plugh}

I tried this on V7, 4.1BSD, 4.2BSD, and UniPlus+ (Sys 3), all
with the same results.

Has anyone seen (and hopefully fixed) this one before?
-- 
  John Bruner (S-1 Project, Lawrence Livermore National Laboratory)
  MILNET: jdb at mordor.ARPA [jdb at s1-c]	(415) 422-0758
  UUCP: ...!ucbvax!dual!mordor!jdb 	...!decvax!decwrl!mordor!jdb



More information about the Comp.unix.wizards mailing list