07-22-2016
Quote:
Originally Posted by
elbrand
and I only wanted to point out that this is an inconsistent behaviour. But, ok, we have two different operators here: (()) and the 'declare' one.
The entire reason (( )) exists is it behaves differently. (( )) is a modern C-style expression where you can mix assignments and comparisons, with a return code like you'd expect of such expressions. It's the modern way to do math and comparison in Bourne shell.
If this is inconsistent with the math syntax of plain Bourne circa 1977, well, good. There's a reason it's considered depreciated for modern shells.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Friends,
I have a file with contents like:
interface Serial0/4/0/0/1/1/1/1:0
encapsulation mfr
multilink
group 101
Now I need to manipulate the file in such a way that to all the numbers less than 163, 63 gets added and to all numbers greater than 163, 63 gets deducted.(The numbers... (2 Replies)
Discussion started by: shrijith1
2 Replies
2. Shell Programming and Scripting
Hello, I'm relatively new to using bc so I could use some help. In this script im working on I want to have the bc function to calculate float numbers for imagemagicks convert charcoal. Below is what I'm talking about. There are no syntax errors but when it outputs the users frames for example 0-10... (2 Replies)
Discussion started by: jsells20
2 Replies
3. Shell Programming and Scripting
Guys,
The below expression is valid in which shells (sh,ksh,bash,csh)?
VAR1=2
VAR2=$(($VAR1 -2))
Thanks (1 Reply)
Discussion started by: rprajendran
1 Replies
4. Shell Programming and Scripting
I use the following shell script in bash and it works fine. It returns 1
# cat /etc/httpd/conf/res.txt
maldet(24444): {scan} scan completed on eicar_com.zip: files 1, malware hits 1, cleaned hits 0
# if ]; then echo 0 > /etc/httpd/conf/malflag; else echo 1 > /etc/httpd/conf/malflag;... (2 Replies)
Discussion started by: anilcliff
2 Replies
5. Shell Programming and Scripting
ls -l /md01/EL/MarketData/inbound/ststr/INVENTORY* |tail -5 |awk '{ print $5,$6,$7,$8,$9 }'If I run the above from the command line the output to md_email is formatted correctly as
78213497 May 1 12:50 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120430.PINESTREET.CSV.done
77904740 May 2... (3 Replies)
Discussion started by: smenago
3 Replies
6. Shell Programming and Scripting
I have 2 numbers
xmin = 0.369000018
xmax = 0.569000006
and want to calculate
(xmax- xmin) / 5.0
I have tried using $(( )) but is always giving an error (8 Replies)
Discussion started by: kristinu
8 Replies
7. Shell Programming and Scripting
Hi,
I have the following code which is giving error mentioned below. Please can you support on this. Also suggest how can we access all the items against single vasservicename in circlename array,i.e, vasservicename say MTSTV will be available to all circles which are mentioned in the array... (2 Replies)
Discussion started by: siramitsharma
2 Replies
8. Shell Programming and Scripting
I am using bash
I have a script that takes a number, i.e. 85.152, which is always a non integer and essentially tries to get that number to be a multiple of 10. My code is as follows:
number=85.152
A=${number%.*} #Converts float to integer
typeset -i B=$(((A-20)/10)) #subtracting 20 is... (12 Replies)
Discussion started by: prodigious8
12 Replies
9. UNIX for Beginners Questions & Answers
Hello everyone,
I need help comparing 2 arrays. the first array is static; the second array is not ..
array1=( "macOS Mojave" "iTunes" )
cd /Volumes
array2=( * )
# output of array2
macOS Mojave
iTunes
Mac me
The problem occurs when I compare the arrays with the following code -
... (6 Replies)
Discussion started by: trexthurman
6 Replies
10. Shell Programming and Scripting
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
LEARN ABOUT OPENDARWIN
integer
integer(3pm) Perl Programmers Reference Guide integer(3pm)
NAME
integer - Perl pragma to use integer arithmetic instead of floating point
SYNOPSIS
use integer;
$x = 10/3;
# $x is now 3, not 3.33333333333333333
DESCRIPTION
This tells the compiler to use integer operations from here to the end of the enclosing BLOCK. On many machines, this doesn't matter a
great deal for most computations, but on those without floating point hardware, it can make a big difference in performance.
Note that this only affects how most of the arithmetic and relational operators handle their operands and results, and not how all numbers
everywhere are treated. Specifically, "use integer;" has the effect that before computing the results of the arithmetic operators (+, -,
*, /, %, +=, -=, *=, /=, %=, and unary minus), the comparison operators (<, <=, >, >=, ==, !=, <=>), and the bitwise operators (|, &, ^,
<<, >>, |=, &=, ^=, <<=, >>=), the operands have their fractional portions truncated (or floored), and the result will have its fractional
portion truncated as well. In addition, the range of operands and results is restricted to that of familiar two's complement integers,
i.e., -(2**31) .. (2**31-1) on 32-bit architectures, and -(2**63) .. (2**63-1) on 64-bit architectures. For example, this code
use integer;
$x = 5.8;
$y = 2.5;
$z = 2.7;
$a = 2**31 - 1; # Largest positive integer on 32-bit machines
$, = ", ";
print $x, -$x, $x + $y, $x - $y, $x / $y, $x * $y, $y == $z, $a, $a + 1;
will print: 5.8, -5, 7, 3, 2, 10, 1, 2147483647, -2147483648
Note that $x is still printed as having its true non-integer value of 5.8 since it wasn't operated on. And note too the wrap-around from
the largest positive integer to the largest negative one. Also, arguments passed to functions and the values returned by them are not
affected by "use integer;". E.g.,
srand(1.5);
$, = ", ";
print sin(.5), cos(.5), atan2(1,2), sqrt(2), rand(10);
will give the same result with or without "use integer;" The power operator "**" is also not affected, so that 2 ** .5 is always the
square root of 2. Now, it so happens that the pre- and post- increment and decrement operators, ++ and --, are not affected by "use
integer;" either. Some may rightly consider this to be a bug -- but at least it's a long-standing one.
Finally, "use integer;" also has an additional affect on the bitwise operators. Normally, the operands and results are treated as unsigned
integers, but with "use integer;" the operands and results are signed. This means, among other things, that ~0 is -1, and -2 & -5 is -6.
Internally, native integer arithmetic (as provided by your C compiler) is used. This means that Perl's own semantics for arithmetic
operations may not be preserved. One common source of trouble is the modulus of negative numbers, which Perl does one way, but your
hardware may do another.
% perl -le 'print (4 % -3)'
-2
% perl -Minteger -le 'print (4 % -3)'
1
See "Pragmatic Modules" in perlmodlib, "Integer Arithmetic" in perlop
perl v5.12.1 2010-04-26 integer(3pm)