radjg@yabbie.rmit.oz (Jordan Green) (03/04/88)
I have been trying to use expr(C) to do some integer manipulation and find that I cannot get the multiplication to work. expr 2 * 3 simply returns 2 * 3 All the other arithmetical functions seem to work so what am I doing wrong with the multiplication? Jordan Green ACSnet: radjg@yabbie UUCP: ...!uunet!munnari!yabbie.rmit.oz!radjg CSNET: radjg@yabbie.rmit.oz ARPA: radjg%yabbie.rmit.oz@uunet.uu.net BITNET: radjg%yabbie.rmit.oz@CSNET-RELAY Post: R & H Australia Pty. Ltd. Phone: + 61 3 699 6611 287 Grant Street, South Melbourne, 3205. Australia
james@bigtex.UUCP (James Van Artsdalen) (03/05/88)
In article <717@yabbie.rmit.oz>, radjg@yabbie.rmit.oz (Jordan Green) writes: > I have been trying to use expr(C) to do some integer manipulation and find > that I cannot get the multiplication to work. > expr 2 * 3 > simply returns > 2 * 3 I'll bet you're entering $ expr "2 * 3" instead of $ expr 2 "*" 3 The first sees the single argument as a string, whereas the second sees three arguments and an arithmetic expression. -- James R. Van Artsdalen ...!uunet!utastro!bigtex!james "Live Free or Die" Home: 512-346-2444 Work: 328-0282; 110 Wild Basin Rd. Ste #230, Austin TX 78746
det@hawkmoon.MN.ORG (Derek E. Terveer) (03/07/88)
In article <717@yabbie.rmit.oz>, radjg@yabbie.rmit.oz (Jordan Green) writes: > I have been trying to use expr(C) to do some integer manipulation and find > that I cannot get the multiplication to work. > expr 2 * 3 > simply returns > 2 * 3 The man page states that multiplication is performed by escaping (using a backslash) the asterisk. Try this: $ expr 2 \* 3 6 $ expr "2 * 3" 2 * 3 $ expr "2 \* 3" 2 \* 3 $ expr 2 * 3 expr: syntax error -- Derek Terveer det@hawkmoon.MN.ORG uunet!rosevax!elric!hawkmoon!det
Unknown@stcns3.stc.oz (Unknown) (03/08/88)
In article <717@yabbie.rmit.oz> radjg@yabbie.rmit.oz (Jordan Green) writes: >I have been trying to use expr(C) to do some integer manipulation and find >that I cannot get the multiplication to work. > >expr 2 * 3 > >simply returns >2 * 3 > >All the other arithmetical functions seem to work so what am I doing wrong with the multiplication? > That's the clue. At a guess, I'd say you need to escape the "*" from the shell. -- Dave Horsfall (VK2KFU) ACS: dave@stcns3.stc.OZ.AU Alcatel-STC Australia ARPA: dave%stcns3.stc.OZ.AU@uunet.UU.NET 11th Floor, 5 Blue St UUCP: {enea,hplabs,mcvax,uunet,ukc}!\ North Sydney NSW 2060 AUSTRALIA munnari!stcns3.stc.OZ.AU!dave
tkevans@fallst.UUCP (Tim Evans) (03/08/88)
In article <717@yabbie.rmit.oz>, radjg@yabbie.rmit.oz (Jordan Green) writes: > I have been trying to use expr(C) to do some integer manipulation and find > that I cannot get the multiplication to work. > > expr 2 * 3 > Backslash the "*"--as in expr 2 \* 3 (The shell is interpreting the asterisk as a normal shell metacharacter) Tim Evans
daveb@laidbak.UUCP (Dave Burton) (03/11/88)
In article <113@hawkmoon.MN.ORG> det@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