Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!phigate!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.unix.questions Subject: Re: Why doesn't this work ? Keywords: /bin/sh Message-ID: <1048@philmds.UUCP> Date: 15 Jun 89 16:07:14 GMT References: <443@fdmetd.uucp> <2761@piraat.cs.vu.nl> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 47 In article <2761@piraat.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: |jon@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.