trouble with expr

Dave Burton daveb at laidbak.UUCP
Fri Mar 11 12:45:58 AEST 1988


In article <113 at hawkmoon.MN.ORG> det at hawkmoon.MN.ORG (Derek E. Terveer) writes:
>The man page states that multiplication is performed by escaping (using a
>backslash) the asterisk.  Try this:

And of course the reason is: the shell will expand that little hummer,
then it won't be a star any more.

Sorry if you know this Derek, but you make it sound like magic. There is
nothing magical about the backslash. The mystery comes from the shell.

>$ expr 2 \* 3
>6
Because expr saw (quotes are mine): '2', '*', '3'
>$ expr "2 * 3"
>2 * 3
Because expr saw '2 * 3' (one argument, not three)
>$ expr "2 \* 3"
>2 \* 3
Becuase expr saw '2 \* 3' (the backslash is protected inside double quotes)
>$ expr 2 * 3
>expr: syntax error
Because expr saw something like '2', 'foo', 'bar', 'etc', '3'.

More fun:
expr 2 '*' 3 = 6
expr 2 "*" 3 = 6
star=*; expr 2 "$star" 3 = 6
-- 
--------------------"Well, it looked good when I wrote it"---------------------
 Verbal: Dave Burton                        Net: ...!ihnp4!laidbak!daveb
 V-MAIL: (312) 505-9100 x325            USSnail: 1901 N. Naper Blvd.
#include <disclaimer.h>                          Naperville, IL  60540



More information about the Comp.unix.xenix mailing list