Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Variables and math in Old skool Bourne Shell Post 302677229 by mr.rhtuner on Wednesday 25th of July 2012 06:53:46 PM
Old 07-25-2012
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:

Code:
let X=10+2*7
Type echo $X and press Enter. You see 24 on the screen.

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:

Code:
$ expr 10 + 2 '*' 7
24 is the answer.

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

I tried:

Code:
$ X=%((10 + 2 '*' 7))
but get the error: synatx error: 'X=% unexpected


Anybody mind giving me an idea what I am doing wrong?
 

9 More Discussions You Might Find Interesting

1. Programming

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.... (1 Reply)
Discussion started by: tonet
1 Replies

2. UNIX for Dummies Questions & Answers

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... (7 Replies)
Discussion started by: knp808
7 Replies

3. Shell Programming and Scripting

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... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies

4. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: madmat
3 Replies

5. Shell Programming and Scripting

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? (7 Replies)
Discussion started by: razen
7 Replies

6. Shell Programming and Scripting

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 ... (2 Replies)
Discussion started by: greycells
2 Replies

7. Shell Programming and Scripting

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 :) (5 Replies)
Discussion started by: jamie_123
5 Replies

8. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: saravanapandi
3 Replies

9. Cybersecurity

'Shell Shock' vulnerability in Bourne shell

A severe vulnerability was discovered in Bourne shell. Just google for: bash vulnerability ... for more details. (5 Replies)
Discussion started by: Cochise
5 Replies
Locale::Codes::LangFam(3pm)				 Perl Programmers Reference Guide			       Locale::Codes::LangFam(3pm)

NAME
Locale::Codes::LangFam - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangFam; $lext = code2langfam('apa'); # $lext gets 'Apache languages' $code = langfam2code('Apache languages'); # $code gets 'apa' @codes = all_langfam_codes(); @names = all_langfam_names(); DESCRIPTION
The "Locale::Codes::LangFam" module provides access to standard codes used for identifying language families, such as those as defined in ISO 639-5. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default ISO 639-5 language family codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language families. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langfam('apa','alpha'); $lext = code2langfam('apa',LOCALE_LANGFAM_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from ISO 639-5 such as 'apa' for Apache languages. This is the default code set. ROUTINES
code2langfam ( CODE [,CODESET] ) langfam2code ( NAME [,CODESET] ) langfam_code2code ( CODE ,CODESET ,CODESET2 ) all_langfam_codes ( [CODESET] ) all_langfam_names ( [CODESET] ) Locale::Codes::LangFam::rename_langfam ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangFam::add_langfam ( CODE ,NAME [,CODESET] ) Locale::Codes::LangFam::delete_langfam ( CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_alias ( NAME ,NEW_NAME ) Locale::Codes::LangFam::delete_langfam_alias ( NAME ) Locale::Codes::LangFam::rename_langfam_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::delete_langfam_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.loc.gov/standards/iso639-5/id.php ISO 639-5 . AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2013-11-04 Locale::Codes::LangFam(3pm)
All times are GMT -4. The time now is 11:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy