Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: Why doesn't this work ? Keywords: /bin/sh Message-ID: <2761@piraat.cs.vu.nl> Date: 14 Jun 89 23:05:43 GMT References: <443@fdmetd.uucp> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 24 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. Anyhow another bug is revealed: the first command between backquotes doesn't generate an error message. 2) The output of `id' is something like: uid=0(root) gid=0(wheel) ^ This space splits the output into TWO words, which `expr' isn't too happy with. Solution: USERID=`expr "\`id\`" : 'uid=\([0-9]*\)(.*'` -- "I HATE arbitrary limits, especially when |Maarten Litmaath @ VU Amsterdam: they're small." (Stephen Savitzky) |maart@cs.vu.nl, mcvax!botter!maart