Sponsored Content
Operating Systems Solaris How to perform addition of two numbers in shell scripting in Solaris-10 Post 302147090 by fpmurphy on Saturday 24th of November 2007 03:54:50 PM
Old 11-24-2007
The following is more portable:

TOTAL=`expr $e4 - $s4`

From the syntax $((expression)) it looks like your script was probably written to take advantage of
specific features in the bash shell. As a result your shell script will not be very portable to
non-Linux/GNU systems unless bash is available on these systems.

Last edited by fpmurphy; 11-24-2007 at 05:02 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to perform calculations using numbers greater than 2150000000.

Could someone tell me how to perform calculations using numbers greater than 2150000000 in Korn Shell? When I tried to do it it gave me the wrong answer. e.g. I have a ksh file with the contents below: --------------------------------- #!/bin/ksh SUM=`expr 2150000000 + 2` PRODUCT=`expr... (3 Replies)
Discussion started by: stevefox
3 Replies

2. Shell Programming and Scripting

Addition of numbers in unix

Hi I have a file with specified format . Hxxxxxxxyyyyyggggggguuuuuuuuuurrrrrrrrrrrrrrrrrrrrrrrr xxxxxxxxyyyyyggggggguuuuuuuuuurrrrrrrrrrrrrrrrrrrrrrrr xxxxxxxxyyyyyggggggguuuuuuuuuurrrrrrrrrrrrrrrrrrrrrrrr xxxxxxxxyyyyyggggggguuuuuuuuuurrrrrrrrrrrrrrrrrrrrrrrr... (3 Replies)
Discussion started by: asinha63
3 Replies

3. Shell Programming and Scripting

Addition of all the numbers in a single file

Hi All , Want to know the "sum" of all the digits in below file called "/sample" .Could some one please let me know the script either command . cat /sample 12 34 23 23 Best Regards, Chinni . (5 Replies)
Discussion started by: chinni-script
5 Replies

4. Shell Programming and Scripting

Addition of floating numbers

Hi, i want to add two decimal values to $ set a= 12.4 $ set b=3.6 $ w=`expr $a - $b` expr: non-numeric argument or is there any other method to do this mathematics operation. i need to use this into my script. (4 Replies)
Discussion started by: dear_abhi2007
4 Replies

5. Shell Programming and Scripting

Help with addition of 2 numbers that are read from a file

I am trying to add free and used memory (so that i can compute percentage used)of remote nodes using shell script. I use the openssh-server,expect tool and ssh script. 1)login.txt (info of nodes): ip1|username|password ip2|username|password . . . 3)sshlogin.sh #!/bin/bash ... (1 Reply)
Discussion started by: marmik1903
1 Replies

6. Shell Programming and Scripting

addition of both positive and negative numbers

Let, I have three numbers +00123.25 -00256.54 +00489.23 I need to sum up all those three numbers, after storing them in three variables (say var1, var2, var3). I used both expr and BC, but they didn't work for me. But, I am not able to sum up them, as I don't have any idea how to... (13 Replies)
Discussion started by: mady135
13 Replies

7. Shell Programming and Scripting

addition of two numbers

by the script, two files Q1 and Q2 will be generated on the system. Q1 will contain an integer number and Q2 also contain an integer number. i would like to add those numbers and put into new file. excerpt from my script 22 subcount=`echo $dir/Q$qid.txt` + `echo $dir/Q$qid.txt` 23 echo... (1 Reply)
Discussion started by: lookinginfo
1 Replies

8. Shell Programming and Scripting

Help with figuring division and addition based on column data and line numbers

I have a data file in the format of 1234 xxx 1234 xxx 1234 xxx 1234 xxxI want to be able to calculate the following - COLUMN1+((LINENUMBER-1)/365) The output needs to preserve the 2nd column - 1234 xxx 1234.00274 xxx 1234.00548 xxx What is the best way to do this? I am somewhat... (9 Replies)
Discussion started by: ncwxpanther
9 Replies

9. Shell Programming and Scripting

Help me to perform count & group by operation in shell scripting?

Hi All, I want to display the distinct values in the file and for each distinct value how may occurance or there. Test data: test1.dat 20121105 20121105 20121105 20121105 20121106 20121106 20121106 20121105 I need to display the output like Output (2 Replies)
Discussion started by: bbc17484
2 Replies

10. Shell Programming and Scripting

Find a matched pattern and perform comparison on numbers next to it

Hi, I have been trying to extract rows that match pattern "cov" with the value next to it to be > 3. The 'cov' pattern may appear either in $3 or $4 (if using ";" as field separator). Below is the example:- input file ... (7 Replies)
Discussion started by: bunny_merah19
7 Replies
hexec(1)																  hexec(1)

NAME
hexec - a process execution hooking tool SYNOPSIS
hexec <OPTIONS> [expr] [cmd] [args...] DESCRIPTION
hexec is a tool to hook into process exececution calls (exec family of syscalls). You can define an expression that is executed against any hooked exec call. This expression may also contain a replacement exec call. OPTIONS SUMMARY
Here is a summary of the options to hexec. --help | -h Print a options/expr summary page --version | -v Print hexec version --log-out | -lo set output file for error and -print output OPTIONS
-h Print a options/expr summary page --help Print a options/expr summary page -lo Set the output file for error and -print output. This can be required if writing to stderr could cause malfunction because some processes read from stderr and expect a well defined output. EXPRESSIONS
The expression is executed against all process execution calls. If the expression returns true, the original call is skipped. <expr> -and <expr> <expr> -a <expr> <expr> <expr> Returns true if both expressions return true. If the left returns false, the right expression is never executed. <expr> -or <expr> <expr> -o <expr> Returns true if one of both expressions returns true. If the left returns true, the right expression is never executed. -path <pattern> Returns true if the path of the executable matches <pattern>. <pattern> is a bash compatible wild card pattern. -ipath <pattern> Same as -path, but case insensitive. -name <pattern> Returns true if the base name of the executable matches <pattern>. <pattern> is a bash compatible wild card pattern. -iname <pattern> Same as -name, but case insensitive. -contains <str> Returns true if the path of the executable containes the string <str>. -icontains <str> Same as -contains, but case insensitive. -print Print all arguments to the called process. Returns always true. -exec <cmd> [args...] ; Executes <cmd> with [args...] as arguments. This expression must be terminated with a semicolon. You can use argument placeholders in <cmd> and [args...] (see below). This expression always returns true. NOTE: Please be aware that you may need to escape or quote the terminating semicolon to not confuse your shell. -sh <script> Interprets <script> as a shell script by invoking /bin/sh with the arguments -c '<script>'. You can use argument placeholders inside <script>. Please note that -sh only expects a single argument and not a variable list of arguments (as -exec does). Using -sh is the same as using -exec sh -c <script>. PLACEHOLDERS FOR -exec EXPRESSION Every -exec expression can use placeholders in the argument list to obtain information from the original exec call. Each placeholder starts with { and ends with }. Use { if you want to use a { in your argument list. The placeholders are replaced when the -exec expression is evaluated. Placeholder types: {n} Will be replaced with the number of arguments in the original call. {<idx>} Will be replaced with the original argument at index <idx>. Example: {1} would give the first argument. You can prepend <idx> with placeholder flags. {} Will be replaced with all arguments from the original call. Each argument is seperated with a space. You can use placeholder flags. NOTE: The executable name is also considered as argument. This means that a call like "echo test" will result in two arguments, "echo" and "test". PLACEHOLDER FLAGS
s Every argument is inserted as single argument instead of concatenating all arguments. Consider the arguments 'a', 'b' and 'c'. Without s, -exec {} ; would result in -exec 'a b c' ;, which in many cases is not what you want. -exec {s} ; howewer would result in -exec 'a' 'b' 'c' ;. q Quote every single argument. e Escape all non alpha-numeric characters. This flag is very useful when using a "sh -c <...>" in the -exec expression. Examples -exec echo {} ; with the call 'a' 'b' 'c' results in: 'echo' 'a b c' -exec echo {q} ; with the call 'a' 'b' 'c' results in: 'echo' 'a' 'b' 'c' -exec sh -c 'echo {}; {}' ; with the call 'sh' '-c' 'gcc d.c >> log.txt' results in: 'sh' '-c' 'echo sh -c gcc d.c >> log.txt; sh -c gcc d.c >> log.txt' Please note that this will not do what you may expect, as the >> is handled wrong in this case. -exec sh -c 'echo {e}; {}' ; with the call 'sh' '-c' 'gcc d.c >> log.txt' results in: 'sh' '-c' 'echo sh -c gcc d.c >> log.txt; sh -c gcc d.c >> log.txt' CHANGES TO PROCESSES
hexec will add some environment variables to the hooked processes. These are (may not be complete): LD_PRELOAD hexec adds libhexec-hook.so to the list of preloaded libraries. HEXEC_EXPR_SHM Contains the name of the internal shared memory object. HEXEC_LOG_FD Contains the file descriptor for error and -print output. Please do never modify these environment variables. Also take care when you use these variables, because the name and content of the vari- ables may change in the future. EXAMPLES
hexec -name 'gcc' -exec ccache {s} ; make Calls make, which will then call gcc several times. The executable name of each hooked process execution is tested against the file pattern "gcc" and "ccache {s}" is called each time a match is found. '{s}' will be replaced with the original (the hooked) call. In this example, a call to "gcc -o test.o test.c" would be replaced with "ccache gcc -o test.o test.c" HOW IT WORKS
TODO BUGS
I'm sure there are alot...it's still beta :) AUTHOR
hexec was written by Alexander Block http://blocksoftware.net/ If you wish to report a problem or make a suggestion then please email ablock@blocksoftware.net hexec is released under the GNU General Public License version 2 or later. Please see the file COPYING for license details. November 2008 hexec(1)
All times are GMT -4. The time now is 01:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy