Sponsored Content
Full Discussion: arithmatic
Top Forums Shell Programming and Scripting arithmatic Post 302700837 by Ygor on Friday 14th of September 2012 09:42:51 AM
Old 09-14-2012
Oh I see the problem. $1 and $2 are local to functions but you are not passing parameters to the function. Perhaps define a and b outside of the functions, e.g...
Code:
$ cat sh.1
menu ()
{
echo "=============="
echo "Calculator"
echo "=============="
echo "1. Divide"
echo "2. Multiply and Subtract"
echo "3. Quit"
read choice
case $choice in
1) option1 ;;
2) option2 ;;
3) exit 0 ;;
*) echo "invalid option" ;;
esac
}

option1 ()
{
c=$(($a/$b))
echo "**********"
echo "****"$c"****"
echo "**********"
}
a=$1
b=$2
menu

$ sh sh.1 50 5
==============
Calculator
==============
1. Divide
2. Multiply and Subtract
3. Quit
1
**********
****10****
**********

$

This User Gave Thanks to Ygor For This Post:
 

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

KSH arithmatic Integer overflow

Guys, I have two big numbers to multiply. In doing do I am getting integer overflow. I managed to multiply number but this number is useless as KSh does not recognise it as a valid number. Here is what I am doing $ expr 999999999999 \* 100 276447132 I got the right value by doing... (2 Replies)
Discussion started by: vikas_sri
2 Replies

2. Shell Programming and Scripting

Unix Arithmatic operation issue , datatype issue

Hi, I have a shell scripting. This will take 7 digit number in each line and add 7 digit number with next subsequent lines ( normal addition ). Eg: 0000001 0000220 0001235 0000022 0000023 ........... ......... ........ Like this i am having around 1500000 records. After adding... (23 Replies)
Discussion started by: thambi
23 Replies

3. Shell Programming and Scripting

arithmatic with awk

hi, i am trying some awk arthmatic calculation,i have a problem if any one can help let say if i have a file exm.txt 3 + 2 3 * 2 3 / 2 3 - 2 the output expected is awk -f exm.awk exm.txt 3 + 2 = 5 3 * 2 = 6 3 / 2 = 1.5 3 - 2 = 1 i simply used exm.awk { print $1 " + " $3 "= " $1 +... (3 Replies)
Discussion started by: phone_book
3 Replies

4. UNIX for Dummies Questions & Answers

Trying a arithmatic on a command line vs scripting.

Hi Everyone! I'm trying to do simple math on a single command line instead of a script which I've already set up using let etc. I can not get the same output to display on a command line. Essentially I would like a=20, b=50, and c=a*b. When I tried: let "A=20, B=50"; let C=A*B; echo $C ... (2 Replies)
Discussion started by: CasperQuiet
2 Replies

5. Shell Programming and Scripting

awk: round output or delimit output of arithmatic string

I have a file with the following content. > cat /tmp/internetusage.txt 6709.296322 30000 2/7/2010 0.00I am using the following awk command to calculate a percentage from field 1 and 2 from the file. awk '{ print $1/$2*100 }' /tmp/internetusage.txt This outputs the value "22.3643" as a... (1 Reply)
Discussion started by: jelloir
1 Replies
mlib_ImageMoment2(3MLIB)				    mediaLib Library Functions					  mlib_ImageMoment2(3MLIB)

NAME
mlib_ImageMoment2 - second moment SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_ImageMoment2(mlib_d64 *moment, const mlib_image *img); DESCRIPTION
The mlib_ImageMoment2() function computes the second moment of each channel in an image. It uses the following equation: 1 w-1 h-1 moment[i] = ----- * SUM SUM img[x][y][i]**2 w*h x=0 y=0 PARAMETERS
The function takes the following arguments: moment Pointer to moment array, where length is the number of channels in the image. img Pointer to an image. RETURN VALUES
The function returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_ImageMoment2_Fp(3MLIB), attributes(5) SunOS 5.10 10 Nov 2004 mlib_ImageMoment2(3MLIB)
All times are GMT -4. The time now is 11:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy