Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Variables and math in Old skool Bourne Shell Post 302677231 by neutronscott on Wednesday 25th of July 2012 06:55:38 PM
Old 07-25-2012
Code:
X=`expr ...`

This User Gave Thanks to neutronscott For This Post:
 

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
expr(1) 						      General Commands Manual							   expr(1)

NAME
expr - evaluate arguments as an expression SYNOPSIS
arguments DESCRIPTION
takes arguments as an expression, evaluates, then writes the result on the standard output. Terms in the expression must be separated by blanks. Characters special to the shell must be escaped. Note that rather than the null string, is returned to indicate a zero value. Strings containing blanks or other special characters should be quoted. Integer-valued arguments can be preceded by a unary minus sign. Internally, integers are treated as 32-bit, 2's complement numbers. The operators and keywords are listed below. Characters that need to be escaped are preceded by The list is in order of increasing prece- dence with equal-precedence operators grouped within symbols. Returns the first expr if it is neither null nor otherwise returns the second expr. In the UNIX 2003 environment, returns 0 if the first expr is null or and the second expr is null. Returns the first expr if neither expr is null or otherwise returns If both arguments are integers, and if the comparison is satisfied, expr returns otherwise it returns expr returns the result of an integer comparison if both arguments are integers; other- wise returns the result of a lexical comparison (note that and are identical, in that both test for equality). Addition or subtraction of decimal integer-valued arguments. Multiplication, division or remainder of decimal integer-valued arguments producing an integer result. The matching operator compares the first argument with the second argument which must be a regular expression. expr supports the Basic Regular Expression syntax (see regexp(5)), except that all patterns are ``anchored'' (i.e., begin with and, therefore, is not a special character, in that context. Normally, the matching operator returns the number of characters matched (0 on fail- ure). Alternatively, the pattern symbols can be used to return a portion of the first argument. The length of expr. Takes the substring of the first expr, starting at the character specified by the second expr for the length given by the third expr. Returns the position in the first expr which contains a character found in the second expr. Match is a prefix operator equivalent to the infix operator Grouping symbols. Any expression can be placed within parentheses. Parentheses can be nested to a depth of as specified in the header file EXTERNAL INFLUENCES
Environment Variables determines the collating sequence used in evaluating regular expressions and the behavior of the relational operators when comparing string values. determines the interpretation of text as single- and/or multi-byte characters, and the characters matched by character class expressions in regular expressions. determines the language in which messages are displayed. If or is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty variable. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to "C" (see environ(5)). If is set to it enables the UNIX 2003 Standard environment. International Code Set Support Single- and multi-byte character code sets are supported. RETURN VALUE
As a side effect of expression evaluation, expr returns the following exit values: Expression is neither null nor zero. Expression is null or zero. Invalid expression. An error occurred while evaluating the expression. DIAGNOSTICS
Operator or operand errors Arithmetic attempted on a string EXAMPLES
Add 1 to the shell variable For equal to either or just return the last segment of a path name (i.e., Beware of alone as an argument because expr interprets it as the division operator (see below): A better representation of the previous example. The addition of the characters eliminates any ambiguity about the division operator and simplifies the whole expression: Return the number of characters in WARNINGS
After argument processing by the shell, expr cannot tell the difference between an operator and an operand except by the value. If is an the command: resembles: as the arguments are passed to expr (and they will all be taken as the operator). The following works: AUTHOR
was developed by OSF and HP. SEE ALSO
sh(1), test(1), environ(5), lang(5), regexp(5). STANDARDS CONFORMANCE
expr(1)
All times are GMT -4. The time now is 06:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy