Using imbedded commands inside expr(1)

Hamish Macdonald himacdon at maytag.uwaterloo.ca
Fri Nov 9 00:58:09 AEST 1990


>>>>> In article <15525 at burdvax.PRC.Unisys.COM>, wrp at PRC.Unisys.COM
>>>>> (William R. Pringle) writes:

William> In article <1462 at eastman.UUCP> gerwitz at kodak.com (Paul
William> Gerwitz) writes:
>I seem to be having trouble using expr.  The following dies:
>
>    test=`expr `tail +3 file` + 1` 
>
>    Basically get a numeric value from a file and increment it,
>    putting the result in a shell variable.

William> The backslash can be used to quote nested backward quotes
William> (and other strange characters):

William> 	test=`expr \`tail +3 file\` + 1`

When using the Korn shell (as the original poster is), I think it is
less confusing to use the $() form of command substitution:

	test=$(expr $(tail +3 file) + 1)

William> Bill Pringle

Hamish.
--
--------------------------------------------------------------------
himacdon at maytag.uwaterloo.ca                 watmath!maytag!himacdon



More information about the Comp.unix.shell mailing list