Help in modulus operator in Bash


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help in modulus operator in Bash
# 1  
Old 12-04-2007
Help in modulus operator in Bash

Hi,

I would like to know given that i have two columns and I would like to take the positive integer of the differences between the two columns.

which means |3-2|=1; |2-3|=1 as well.

I would like to know do Bash recognize | | as well for this purposes?


Thanks.

-Jason
# 2  
Old 12-04-2007
I don't think so ! You should perhaps use the expr command to do some basic mathematical command, but only with integer ! You can use it in a bash script !
# 3  
Old 12-04-2007
Code:
a=100
b=200
((x=a-b))
x=${x#-}

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash variable assignment failure/unary operator expected

I have a little code block (executing on AIX 7.1) that I cannot understand why the NOTFREE=0 does not appear to be assigned even though it goes through that block. This causes a unary operator issue. #!/bin/bash PLATFORM="AIX" NEEDSPC=3000 set -x if ; then lsvg | grep -v rootvg | while... (6 Replies)
Discussion started by: port43
6 Replies

2. Shell Programming and Scripting

Operator test in bash

Hello, can you please help me because I am totally confused with a simple script: #!/bin/bash ] || ] && echo "Good Morning" ] || ] && echo "Good Night" For me, these two strings are indentical: false || false and there is no point to execute echo command. But the run result is... (5 Replies)
Discussion started by: AndreiM
5 Replies

3. Shell Programming and Scripting

Equivalent to Perl's and Bash's "=~" Operator?

Hello All, Alright, so this is driving me absolutely insane. I can't seem to find this ANYWHERE... I've tried every combination and synonym I can think of for this trying to search Google. What is the Expect/Tcl equivalent to Perl and Bash's "=~" operator, (i.e. the "contains" operator).... (2 Replies)
Discussion started by: mrm5102
2 Replies

4. Shell Programming and Scripting

bash script error with binary operator expected.

Hello, I am not sure, where I am missing in the scirpt, I am trying to grep few users from /etc/passwd file and if exists, I added line to echo as user exist, if not create it. #!/bin/bash for vid in v707 z307 z496 z163 z292 ; do if then echo " $vid User exists " else ... (2 Replies)
Discussion started by: bobby320
2 Replies

5. UNIX for Dummies Questions & Answers

Help on Modulus

Hello All, I am trying to do a simple calculation using modulus (%) as shown below. But some how it is not showing me correct result. It says "0.166667" is equal to "0" which is wrong. Could you please help me how can i make it work. Thanks a lot. #!/bin/ksh attempt_count=10 SLEEP=60... (7 Replies)
Discussion started by: Ariean
7 Replies

6. Shell Programming and Scripting

cannot properly employ "or" operator in an if statement (bash)

Hi, I have a variable, $sername, and I would like to display this variable only if it *does not* contain either of these two tags: *DTI*FA* or *DIFF*FA*. I think the syntax for my 'or' operator is off. The variable $sername is continuously changing in an outer loop (not shown), but at the... (4 Replies)
Discussion started by: goodbenito
4 Replies

7. Shell Programming and Scripting

chomp like Perl operator in Bash

I am sure there should exist a chomp like Perl operator in Bash using which I can literally remove new line characters as show below: Any clue? (3 Replies)
Discussion started by: paragkalra
3 Replies

8. Shell Programming and Scripting

awk Division and modulus

I need to read the file divide 3 column with 2nd and run a modulus of 10 and check whether the remainder is zero or not if not print the entire line. cat filename | awk '{ if ($3 / $2 % 10 != 0) print $0}' Whats wrong with it ? (4 Replies)
Discussion started by: dinjo_jo
4 Replies

9. Shell Programming and Scripting

FIle (directory) test operator (bash)

I'm almost pulling out my hair trying to figure out what's wrong with this... there's no reason I can see that it shouldn't be working. It seems that the code acts as though the conditional statement is true no matter what - I've even tried removing the negation operator, but it always goes into... (5 Replies)
Discussion started by: wildbluefaerie
5 Replies

10. Shell Programming and Scripting

Modulus operator

What is the modulus operator in korn shell?? (5 Replies)
Discussion started by: manash.paul
5 Replies
Login or Register to Ask a Question