Sponsored Content
Full Discussion: String Arithmetic ?
Top Forums UNIX for Dummies Questions & Answers String Arithmetic ? Post 302336757 by Franklin52 on Wednesday 22nd of July 2009 06:10:58 PM
Old 07-22-2009
Remove the backticks (`) from this line:

Code:
scanFromLine=`$(( ${totalLines} - ${scanFromLine} ))` ## this line throws an error

Regards
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

time arithmetic

Can anyone help please. I am writing a kourne shell script and I am unsure how to do the following: I have extracted a time string from a logfile, and I have another time string I want to compare it to to see if it's later than the time I'm comparing with. i.e. expectedSLA="23:00:00", ... (2 Replies)
Discussion started by: csong2
2 Replies

2. UNIX for Dummies Questions & Answers

arithmetic problem

i am used to making scripts for hp-ux. but lately i tried to make some for solaris. the problem is that when i tried to execute it it gave me an error the "let: not found". why is that? how can i perform an arithmetic function in the solaris shell script? thanks :) (2 Replies)
Discussion started by: inquirer
2 Replies

3. UNIX for Dummies Questions & Answers

arithmetic syntax

okay, I'm a complete beginner, and I keep getting stuck on the syntax here. I want to write a script where I read the current time as minutes and seconds, convert the minutes to seconds, and add the two, then redirect the output to a file. the command takes two arguments, which will also be... (1 Reply)
Discussion started by: paprbagprincess
1 Replies

4. Shell Programming and Scripting

Can I use wc -l with arithmetic expression?

Folks, I am wondering that i can use something like this in one line. For example, $((cat filename > wc -l) / 2) It doesn't work; how to get it work using command substitution? Moreover, is there any option for wc -l not to return filename after the line counts? wc -l filename would... (3 Replies)
Discussion started by: lalelle
3 Replies

5. Shell Programming and Scripting

Help with arithmetic operation

I am using egrep to extract numbers from a file and storing them as variables in a script. But I am not able to do any arithmetic operations on the variables using "expr" because it stores them as char and not integers. Here is my code and the error I get. Any help will be appreciated. #!/bin/sh... (3 Replies)
Discussion started by: emjayshaikh
3 Replies

6. Shell Programming and Scripting

arithmetic in tcsh

Yes I know tcsh sucks for scripting and arithmetic but I have to write a script for multiple users and they all use tcsh. I have this variable that I 'set' with but pulling numbers off of stings with set STUFF = `grep string file | awk command` Now I would like to add up the numbers that... (4 Replies)
Discussion started by: gobi
4 Replies

7. UNIX for Dummies Questions & Answers

Arithmetic: how to??

Hello all, I'd like to know how to perform arithmetic on multiple files. I have got many tab-delimited files. Each file contains about 2000 rows and 2000 columns. What I want to do is to to sum the values in each row & column in every file. The following explains what I want to do; ... (9 Replies)
Discussion started by: Muhammad Rahiz
9 Replies

8. Shell Programming and Scripting

csh arithmetic ?

Hello, Could someone explain how this one is possible: # @ x = 10 - 11 + 3 # echo $x -4 I know that writing script using csh is bad idea, but I need to write few lines. thanks Vilius (2 Replies)
Discussion started by: vilius
2 Replies

9. UNIX for Beginners Questions & Answers

Invalid arithmetic operator on string concatenation

Hello. LEAP_VERSION="4.2" export ARRAY_MAIN_REPO_LEAP=('zypper_local' 'openSUSE-Leap-'"$LEAP_VERSION"'-Non-Oss' 'openSUSE-Leap-'"$LEAP_VERSION"'-Oss' 'openSUSE-Leap-'"$LEAP_VERSION"'-Update' 'openSUSE-Leap-'"$LEAP_VERSION"'-Update-Non-Oss')Seems that the - is interpreted as a numeric... (2 Replies)
Discussion started by: jcdole
2 Replies

10. Shell Programming and Scripting

Arithmetic with bash

I need to divide the number of white spaces by total number of characters in a file using bash. I am able to get the number of white spaces correctly using: tr -cd < afile | wc -c I am also able to get the total number of characters using: wc -c afile How do I divide the first... (2 Replies)
Discussion started by: ngabrani
2 Replies
CHECK_INT32_ADD(3)					   BSD Library Functions Manual 					CHECK_INT32_ADD(3)

NAME
check_int32_add, check_uint32_add, check_int64_add, check_uint64_add, check_int32_sub, check_uint32_sub, check_int64_sub, check_uint64_sub, check_int32_mul, check_uint32_mul, check_int64_mul, check_uint64_mul, check_int32_div, check_uint32_div, check_int64_div, check_uint64_div, -- detect overflow in arithmetic SYNOPSIS
#include <checkint.h> int32_t check_int32_add(int x, int y, int *err); uint32_t check_uint32_add(int x, int y, int *err); int64_t check_int64_add(int x, int y, int *err); uint64_t check_uint64_add(int x, int y, int *err); int32_t check_int32_sub(int x, int y, int *err); uint32_t check_uint32_sub(int x, int y, int *err); int64_t check_int64_sub(int x, int y, int *err); uint64_t check_uint64_sub(int x, int y, int *err); int32_t check_int32_mul(int x, int y, int *err); uint32_t check_uint32_mul(int x, int y, int *err); int64_t check_int64_mul(int x, int y, int *err); uint64_t check_uint64_mul(int x, int y, int *err); int32_t check_int32_div(int x, int y, int *err); uint32_t check_uint32_div(int x, int y, int *err); int64_t check_int64_div(int x, int y, int *err); uint64_t check_uint64_div(int x, int y, int *err); DESCRIPTION
The check_<type>_<operation>(x, y, err) family of functions perform the specified arithmetic operation (addition, subtraction, multiplica- tion, or division) with the left operand of x and right operand of y and return the arithmetic result with the specified type. Either operand x or y (or both) can be of any type that is compatible to signed or unsigned 8-bit, 16-bit, 32-bit, or 64-bit integers. The err argument is or'ed by flags in the function to indicate if an overflow has occurred. The possible flag values are: CHECKINT_NO_ERROR no overflow has occurred CHECKINT_OVERFLOW_ERROR overflow has occurred CHECKINT_TYPE_ERROR operand is of an incompatible type The err argument is not cleared in calls to the check_<type>_<operation>(x, y, err) functions. Detected overflow persists in the err argu- ment until err is reset to CHECKINT_NO_ERROR. RETURN VALUES
If successful, the check_<type>_<operation>() functions will return the arithmetic result of performing the operation with left operand x and right operand y (even when overflow error occurs). If any other error occurs, the return value is -1 and the argument err will be set to indicate the error. EXAMPLES
/* Create a variable to store overflow flag */ int32_t err = CHECKINT_NO_ERROR; /* Use checkint API to perform an arithmetic operation and * store result in variable. */ int32_t arithmetic_result = check_int32_add(UINT_MAX, 1, &err); /* Check status of overflow flag */ if (err & CHECKINT_OVERFLOW_ERROR) { /* Perform overflow resolution code */ fprintf(stderr, "Overflow detected! "); } /* Check for type error */ else if (err & CHECKINT_TYPE_ERROR) { /* Deal with incompatible types error */ fprintf(stderr, "Incompatible types! "); } /* Reset overflow flag for next operation */ err = CHECKINT_NO_ERROR; ERRORS
The check_<type>_<operation>() functions may fail if: [CHECKINT_TYPE_ERROR] operand is of an incompatible type HISTORY
The checkint() API was introduced in Mac OS X 10.5. BSD
April 20, 2007 BSD
All times are GMT -4. The time now is 12:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy