Tagged Questions
2
votes
1answer
66 views
Difference between two types of shell arithmetic
What is the difference between the following two shell arithmetic commands:
echo $[ $var1 - 1 ]
echo $(( $var1 - 1 ))
Assuming var1 = 5 for example.
1
vote
2answers
71 views
case + how to implement equal or less or greater in case syntax
My target is to verify a range of number with (only with case + esac), and print the range. So for example:
If the number is between 0 and 80, print >=0<=80
If the number is between 81 and 100 ...
6
votes
5answers
624 views
Binary to hexadecimal and decimal in a shell script
I have a context where I need to convert binary to hexadecimal and decimal and viceversa in a shell script. Can someone suggest me a tool for this?
3
votes
2answers
194 views
Error when subtracting two negative numbers in ksh: “assignment requires lvalue”
I am trying to debug someone else's script:
The code line is:
y=$((${oldvalue[$x]}-${newvalue[$x]}))
y gets calculated fine as long as both sides are positive numbers. However, I have a ...
0
votes
2answers
156 views
How to add arithmetic variables in a script
I want to accumulate the line size of a number of files contained in a folder. I have written the following script:
let a=0
let num=0
for i in folder/*
do
num=`cat $i | wc -l`
...
10
votes
5answers
3k views
How to compare to floating point number in a shell script
I want to compare two floating point numbers in a shell script. The following code is not working:
#!/bin/bash
min=12.45
val=10.35
if (( $val < $min )) ; then
min=$val
fi
echo $min
1
vote
3answers
345 views
Writing a shell script to take output of an executable and perform some calculation
I am not much familiar with shell script. I want to write a shell script for the following pseudo-code:
min=some garbage value
for(i=1 to N){ // N and n will be taken as input for the shell script.
...
