## Variables and math in Old skool Bourne Shell

# 1
Variables and math in Old skool Bourne Shell

Hey everybody, I've been searching google and these forums and have found some solutions to the issues I've been having today within the OLD Bourne Shell. I am following chapter 6 of the Guide to Unix using Linux 4th Edition.

I am working on some basic calculations with variables in the BASH SHELL and doing the same within the Bourne Shell with modifications.

In BASH, I did the following:

Now I realize that the bourne shell does NOT have LET as a command, and I need to use expr.

I was able to get the math to work, by doing the following:

But how do I incorporate the variable of X into this?

I tried:

Anybody mind giving me an idea what I am doing wrong?
 mr.rhtuner View Public Profile for mr.rhtuner Find all posts by mr.rhtuner
# 2
This User Gave Thanks to neutronscott For This Post:
 neutronscott View Public Profile for neutronscott Visit neutronscott's homepage! Find all posts by neutronscott
# 3
Quote:
Originally Posted by neutronscott

Thank you for the guidence.

I was able to get it.

Here is what I wrote out:

'

So I got X as the variable holding the answer of 24....Thank you very much!
 mr.rhtuner View Public Profile for mr.rhtuner Find all posts by mr.rhtuner
# 4
Both expr and bc are external commands and therefore nothing to do with the Shell.

I prefer bc because it can handle both simple and complex formuli:

Many will note that this works but is less easy to read:
 methyl View Public Profile for methyl Find all posts by methyl

## Doing math using user defined input and system environment variables

Hi, I need some help to setup some environmental variables. for example...Get A -> userdefined/user input B -> a number. c -> system variable...for example \$GETCONF PAGE_SIZE E = do some math using bc display a message "The value is E" setup the system/kernel paramter sysctl -p...

## Math calculation over shell

Hi I am trying to calculate the rate at which something is happening. I have 2 files- a1 and b1. I want to calculate something like this ((wc -l a1)/(wc -l a1 + wc -l b1))*100 over a loop for different a and b. Is this possible, help me out fellas. Thanks a lot :)

## Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. \$ echo \$SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get...

## A Math problem using shell script

Have a bit complicated math query .. Basically i am given a number which is > 50 .. I am suppose to find the calculation to get a number which is equal or more than the input number and is also a multiple of any number between 20 - 30 . For example . Input number is 60 . Now 20x3 =60 ...

## assigning two variables in bourne shell

there are two variables from a select query and these two variables has to assign in a update query . the two variables are two fields. How to assign without splitting by awk?

## How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat \${file1} | tail -\$((\${num1}-\${num2})) > \${file2} Is it possible to activate Korn Shell...

## I need to understand the differences between the bash shell and the Bourne shell

I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done. I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and...

## Can Any help me with the math on this shell script?

Develop a grade calculating program. This program will process all students in the file. This program should neatly display each field of each student's record *and* adds the following items: Course Average and Letter Grade. The course average is calculated by the following weights: 50% for quiz...

## Math with user variables

Hi everybody: I have a problem about use variables. I 've created this variable: var=`wc -l file.txt | cut -c 1-2`; n_var="\$var"-1 ; echo \$n_var; In my case var is 8. When echo shows \$n_var does not appear as I want. The question is how can I subtract, this is operate, to my variable....