---Ash数学运算

扫码查看
> -----Original Message-----
> From: busybox-bounces at mail.busybox.net
> [mailto:busybox-bounces at mail.busybox.net] On Behalf Of Aizer
> Danny-BDA023
> Sent: Monday, January 17, 2005 07:34
> To: BusyBox (E-mail)
> Subject: [BusyBox] BusyBox ash arithmetic operations
>
> Hello,
>
> I was trying to find out whether BusyBox supports simple arithmetic
> operations with variables.

Well, it depends on which shell you use, as BusyBox contains
four different shells. Ash supports it, and I think msh does too.
If you use ash, then you should enable CONFIG_ASH_MATH_SUPPORT
to get arithmetic support.

The syntax for the arithmetic expressions follow the standard
posix shell (IEEE 1003.1) arithmetic syntax (i.e., the same as
bash uses).

> E.g., something like:
>
> wc1=`wc -l file1`
> wc2=`wc -l file2`
>
> total=$wc1 + $wc2			?????

total=$(( $wc1 + $wc2 ))

> if [ $total > MAX_WC ]; then

if [ $total -gt MAX_WC ]; then

> 	echo "squeak"
> fi
>
> If it does not support such operations, is there any "workaround"?
>
> Thanks,
> /Danny

//Peter

10-27 23:46
查看更多