From: Jack on
In my script, I do this:

a=100
b='expr $a \* 2'


The error is:
expr $a \* 2: integer expression expected



Thanks.
From: Chris F.A. Johnson on
On 2010-05-11, Jack wrote:
> In my script, I do this:
>
> a=100
> b='expr $a \* 2'
>
>
> The error is:
> expr $a \* 2: integer expression expected

You wouldn't get that error from the code you posted (even if you
posted what you actually ran).

And why are you using expr? All standard Unix shells have
arithmetic builtin:

b=$(( $a * 2 ))

--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
===== My code in this post, if any, assumes the POSIX locale =====
===== and is released under the GNU General Public Licence =====
From: David W. Hodgins on
On Mon, 10 May 2010 23:12:23 -0400, Jack <junw2000(a)gmail.com> wrote:

> In my script, I do this:
> a=100
> b='expr $a \* 2'
> The error is:
> expr $a \* 2: integer expression expected

You've used single quotes where backticks are expected. On a U.S.
style keyboard, this is usually just to the left of the 1 key.

a=100
b=`expr $a \* 2`

See http://tldp.org/LDP/abs/html/arithexp.html for some more
information.

Regards, Dave Hodgins

--
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)
From: Keith Thompson on
"David W. Hodgins" <dwhodgins(a)nomail.afraid.org> writes:
> On Mon, 10 May 2010 23:12:23 -0400, Jack <junw2000(a)gmail.com> wrote:
>
>> In my script, I do this:
>> a=100
>> b='expr $a \* 2'
>> The error is:
>> expr $a \* 2: integer expression expected
>
> You've used single quotes where backticks are expected. On a U.S.
> style keyboard, this is usually just to the left of the 1 key.

No, he's *posted* single quotes where backticks are expected.
If he had actually *used* single quotes, he would simply have set
$b to the string 'expr $a \* 2', and he wouldn't have gotten the
error message he reported.

I'm not sure what he actually used that would have produced that
particular error message (no doubt it depends on which implementation
of "expr" he's using).

[...]

Note that for most, but probably not all, Bourne-derived shells,
there's an alternative syntax for command substitution:

b=$(expr $a \* 2)

Or, as Chris F.A. Johnson already pointed out, you can (probably) use
the shell's built-in arithmetic:

b=$(($a * 2))

--
Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
From: Eric on
On 2010-05-12, Keith Thompson <kst-u(a)mib.org> wrote:
> "David W. Hodgins" <dwhodgins(a)nomail.afraid.org> writes:
>> On Mon, 10 May 2010 23:12:23 -0400, Jack <junw2000(a)gmail.com> wrote:
>>
>>> In my script, I do this:
>>> a=100
>>> b='expr $a \* 2'
>>> The error is:
>>> expr $a \* 2: integer expression expected
>>
>> You've used single quotes where backticks are expected. On a U.S.
>> style keyboard, this is usually just to the left of the 1 key.
>
> No, he's *posted* single quotes where backticks are expected.
> If he had actually *used* single quotes, he would simply have set
> $b to the string 'expr $a \* 2', and he wouldn't have gotten the
> error message he reported.
>
> I'm not sure what he actually used that would have produced that
> particular error message (no doubt it depends on which implementation
> of "expr" he's using).
>

Can't reproduce it here, but I suspect that for some shell or other,
taking the posted script as a true copy and assuming an explicit or
somehow implicit

typeset -i b

ahead of it would be likely to give that sort of message. I get

expr $a \* 2: syntax error: invalid arithmetic operator

E.