Why doesn't this work ?

Leo de Wit leo at philmds.UUCP
Fri Jun 16 02:07:14 AEST 1989


In article <2761 at piraat.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
|jon at fdmetd.uucp (Jon Ivar Tr|stheim) writes:
|\Why does not the following command work in a Bourne shell script ?
|\
|\	USERID=`expr "`id`" : 'uid=\([0-9]*\)(.*'`
|               ^      ^  ^                       ^
|	       |      |  |                       |
|	       +------+  +-----------------------+
|
|1) As shown above, sh doesn't parse the expression the way you intended.
|   I consider this a bug.

This is definitely NOT a bug, but the way shell quoting is documented
to behave. From S.R.Bourne, 'An Introduction to the UNIX Shell':

The following table gives, for each quoting mechanism, the shell
metacharacters that are evaluated.

					metacharacter
		\	$	*	`	"	'
	'	n	n	n	n	n	t
	`	y	n	n	t	n	n
	"	y	y	n	y	t	n

		t	terminator
		y	interpreted
		n	not interpreted

(end of quote 8-)
So, between `` the " metacharacter is to be taken literal (it is
of course interpreted in the forked shell).

|   Anyhow another bug is revealed: the first command between backquotes
|   doesn't generate an error message.

Strictly speaking you are correct; for some reason sh accepts
end-of-file as terminator of (any?) quoting. The following script that
has a comparable error, doesn't draw an error message either:

------ start of script ------
#! /bin/sh

echo "
Where does it all end ...
------ end of script ------

    Leo.



More information about the Comp.unix.questions mailing list