I found the following issue by simply increasing a variable. The
expression returns an error, the other expressions both return 0. Does anyone know why?
Hm, I found the point in the man page now. It was imho a bad decision to change the behaviour of the (()) expression. Why should a successful expression return a non zero exit code?
You are aware what $? means, yes? It's a return code. It is not a mathematical result, but it is the result of the expression.
The result of the expression (( X = 0 )) is zero, which considered as a boolean means false, which as a return code means failure, so $? becomes 1.
The result of (( X = 1 )) is nonzero, which considered as a boolean means true, which as a return code means success, so $? becomes 0.
It does this because this is how mathematical functions work in most languages, which is what (( )) is for. If you don't want to do that, there's the old fashioned way.
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)
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)
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)
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)
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)
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)
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)
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)
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)