bin bash decimal compare


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bin bash decimal compare
# 8  
Old 07-27-2012
Hi,

Code:
#!/bin/bash

apachever=$(/usr/local/apache/bin/httpd  -v | head -1 | awk '{print $3}' |cut -d/ -f 2)
minval=$( echo -e "$apachever\n2.2.17" | sort -n -t . -k 1,1 -k 2,2 -k 3,3 | head -1 )

if [ "$minval" = "2.2.17" ]; then
	echo "Apache version $apachever greater or equal to 2.2.17"
else
	echo "Apache version $apachever less than 2.2.17"
fi

This User Gave Thanks to Chirel For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts: 1.) Are the commands of the base shell scripts a subset of bash commands? 2.) Assume I got a long, long script WITHOUT the first line. How can I find out if the script was originally designed für "sh" or "bash"? 3.) How can I check a given... (3 Replies)
Discussion started by: pstein
3 Replies

3. Shell Programming and Scripting

How to compare decimal values in bash?

Hi, I am facing some error while doing the comparision between 2 decimal values in bash. Pl help me out. I have tried using below scripts. But its giving me error. 1)amt=12.3 opn_amt=12.5 var=$(awk 'BEGIN{ print "'$amt'"<"'$opn_amt'" }') if ;then echo "correct" else echo "Wrong"... (3 Replies)
Discussion started by: Siba Tripathy
3 Replies

4. Shell Programming and Scripting

How compare decimal values?

I have 2 files say tp1.txt and tp2.txt having following data cat tp1.txt abc,2.20,IN20 acb,3.15,DN10 bca,3,RD10 cat tp2.txt alv,1.00,IN20 aaa,4.05,DD10 abb,5.50,RD12 i want to compare the values on 2nd field of both the file, if value of first tp1.txt is greater than value... (3 Replies)
Discussion started by: ranabhavish
3 Replies

5. Shell Programming and Scripting

BIN/BASH.

THANKS UNIX SYSTEM®.I was found my job from UNIX®.I USE MONKEY WRENCH WITH WARTER.I am now studying my studio with UNIX SYSTEM®. THANKS UNIX SYSTEM®. THANKS OUR OPEN GROUP. from Takayasu Sakashita.My name is Takayasu Sakashita. I respect you. Austin.PEACE!Bey bey. Your friend TAKA.Good... (1 Reply)
Discussion started by: administrator®
1 Replies

6. UNIX for Dummies Questions & Answers

compare decimal and integer values in if in bash shell

i need to do camparisions like the below. For the case when first=10 and second=9.9 the scripts displays process failed. I need to be able to convert the values to integer before doing the comparision. Like 9.9 should be rounded over to 10 before doing comparision. Please advice how can... (3 Replies)
Discussion started by: nehagupta
3 Replies

7. Shell Programming and Scripting

Compare float value with single decimal

#!/bin/bash filter_file=/export/home/alvin/test.txt range1_count=0 range2_count=0 categorized(){ value=$1 if # range 5.1 to 10.0 then range1_count=`expr $range1+ 1` elif # range 5.1 to 15.00 then range2_count=`expr $range2+ 1` fi } #read txt file which contain lines of... (8 Replies)
Discussion started by: alvin0618
8 Replies

8. Shell Programming and Scripting

Bash Decimal Addition using bc

Hi guys/gals i have a quick question. I am trying to read from a file and add the values up but the problem is the values are not integers their floats so i tried to used bc but failed epicly lol. Any tips would be great. Thanks this is the code i have so far : while read num do ... (6 Replies)
Discussion started by: vb615
6 Replies

9. Shell Programming and Scripting

Compare integer value with decimal

Hi all, I have a issue... Is it possible to compare integer value with decimal value. If it is not possible,then how can i compare 2 decimal values in born shell.thanks! (3 Replies)
Discussion started by: MARY76
3 Replies

10. Shell Programming and Scripting

compare decimal numbers

Hi anyone, i need to compare two decimal numbers i thought that it could be do it with if but... :( So, i'm writing in csh and i really apreciate if anyone can help me if ( $ppl_kn <= $ppl_wb ) then echo "############# KNdiscount model has the lowest perplexity" set... (5 Replies)
Discussion started by: tmxps
5 Replies
Login or Register to Ask a Question
CHECKBASHISMS(1)                                              General Commands Manual                                             CHECKBASHISMS(1)

NAME
checkbashisms - check for bashisms in /bin/sh scripts SYNOPSIS
checkbashisms script ... checkbashisms --help|--version DESCRIPTION
checkbashisms, based on one of the checks from the lintian system, performs basic checks on /bin/sh shell scripts for the possible presence of bashisms. It takes the names of the shell scripts on the command line, and outputs warnings if possible bashisms are detected. Note that the definition of a bashism in this context roughly equates to "a shell feature that is not required to be supported by POSIX"; this means that some issues flagged may be permitted under optional sections of POSIX, such as XSI or User Portability. In cases where POSIX and Debian Policy disagree, checkbashisms by default allows extensions permitted by Policy but may also provide options for stricter checking. OPTIONS
--help, -h Show a summary of options. --newline, -n Check for "echo -n" usage (non POSIX but required by Debian Policy 10.4.) --posix, -p Check for issues which are non POSIX but required to be supported by Debian Policy 10.4 (implies -n). --force, -f Force each script to be checked, even if it would normally not be (for instance, it has a bash or non POSIX shell shebang or appears to be a shell wrapper). --extra, -x Highlight lines which, whilst they do not contain bashisms, may be useful in determining whether a particular issue is a false posi- tive which may be ignored. For example, the use of "$BASH_ENV" may be preceded by checking whether "$BASH" is set. --version, -v Show version and copyright information. EXIT VALUES
The exit value will be 0 if no possible bashisms or other problems were detected. Otherwise it will be the sum of the following error val- ues: 1 A possible bashism was detected. 2 A file was skipped for some reason, for example, because it was unreadable or not found. The warning message will give details. SEE ALSO
lintian(1). AUTHOR
checkbashisms was originally written as a shell script by Yann Dirson <dirson@debian.org> and rewritten in Perl with many more features by Julian Gilbey <jdg@debian.org>. DEBIAN Debian Utilities CHECKBASHISMS(1)