-gt [greater than] comparitive operator across the paltform


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting -gt [greater than] comparitive operator across the paltform
# 1  
Old 09-14-2016
Computer -gt [greater than] comparitive operator across the paltform

Hi I am using -gt comparative operator in one of my shell script.

I have tested that in Linux platform but same code will go in many other platforms i.e.
  • HPI
  • HPUX
  • Solaris
  • zLinux
  • SolarisSparc
Somehow I do not have access to all the servers with these OS...



Can someone suggest that how to confirm that greater than operator will work in all the platforms.


Thanks, Ambar

Last edited by rbatte1; 09-14-2016 at 08:31 AM.. Reason: Corrected LIST
# 2  
Old 09-14-2016
The comparison will be shell specific, so the question we need to ask is 'What shell are you running on each platform?'

Can you also show us the area of code that is failing so we can suggest something more portable.


Thanks,
Robin
# 3  
Old 09-14-2016
Quote:
Originally Posted by rbatte1
The comparison will be shell specific
Sorry to correct you, but the behavior of "test" (/usr/bin/test) is standardized by POSIX and "-gt" can be expected to work in a certain way on every standard-conformant platform, regardless of the shell.

This (the aforementioned) is true for constructs like:

Code:
[ .... -gt .... ]

and
Code:
/usr/bin/test .... -gt ....

Shell-dependant is this:

Code:
[[ .... -gt .... ]]

because "[[" is a (shell-builtin) replacement for "[" and "test" and hence depending on the shell it is built into. Some shells (for incstance the ksh88 on AIX) implements "[" as a shell-builtin too, but if this is the case it should conform to the POSIX-standard, whereas the standard says nothing about "[[".

I hope this helps.

bakunin
# 4  
Old 09-15-2016
[ .... -gt .... ] in /bin/sh runs on all Unix-like platforms in an identical way (compares integers and sets exit status).
# 5  
Old 09-15-2016
Quote:
Originally Posted by bakunin
Sorry to correct you, but the behavior of "test" (/usr/bin/test) is standardized by POSIX and "-gt" can be expected to work in a certain way on every standard-conformant platform, regardless of the shell
To add: -gt also works in non-Posix shells, like Bourne shell and KSH88, any shell as long as it is Bourne-shell derived (so not csh or tcsh)..

Quote:
This (the aforementioned) is true for constructs like:

Code:
[ .... -gt .... ]

and
Code:
/usr/bin/test .... -gt ....

Shell-dependant is this:

Code:
[[ .... -gt .... ]]

because "[[" is a (shell-builtin) replacement for "[" and "test" and hence depending on the shell it is built into. Some shells (for incstance the ksh88 on AIX) implements "[" as a shell-builtin too, but if this is the case it should conform to the POSIX-standard, whereas the standard says nothing about "[[".
[..]
[ ... ] or test is also a shell builtin utility in every implementation I know of posix compliant shells
[[ ... ]] is not a shell builtin utility, but are shell keywords (part of the shell syntax) (They are indeed not part of the POSIX specification, so only supported in certain shells (ksh, zsh, bash)).

Code:
$ type test \[ \[\[ \]\]
test is a shell builtin
[ is a shell builtin
[[ is a shell keyword
]] is a shell keyword


Last edited by Scrutinizer; 09-16-2016 at 01:06 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Egrep a greater than number

data: hello mr smith 400 you all ok? hello mrs. smith 700 you all ok? hello mr. everyone 150 you all ok? hello mr. you all 199 im lad you are ok using egrep, how can i grep out only lines that have a number greater than 250? cat data | egrep ..... can't use awk here. i was... (7 Replies)
Discussion started by: SkySmart
7 Replies

2. Shell Programming and Scripting

How to search for numbers greater than x?

I have a file with multiple fields, example below File 1: Field 1|Field 2|Field 3|Field 4|Field 5|Field 6|Field 7|100 Field 1|Field 2|Field 3|Field 4|Field 5|Field 6|Field 7|101 Field 1|Field 2|Field 3|Field 4|Field 5|Field 6|Field 7|102 Field 1|Field 2|Field 3|Field 4|Field 5|Field... (4 Replies)
Discussion started by: castrojc
4 Replies

3. Shell Programming and Scripting

greater than a certain value

I have an output from db which looks like : row1 row2 row3 abc 21.1 13 efg 21.1 45 ghi 21.1 75 when I apply following command ( cat my_output.txt | awk {'print $ 4' } I have following output : row3 13 45 75 now I want to figure out if... (4 Replies)
Discussion started by: kvok
4 Replies

4. Shell Programming and Scripting

find greater than value

Hi I want to find greater than and min value. dategrep() { varlinenum=$1 varSESSTRANS_CL="$(egrep -n "<\/SESSTRANSFORMATIONINST>" tmpsess9580.txt | cut -d":" -f1)" echo $varSESSTRANS_CL } dategrep 8 Output of the above command is: I want to find out greater than 8 and... (9 Replies)
Discussion started by: tmalik79
9 Replies

5. Shell Programming and Scripting

Problem with Greater Than Or Equal To

BASH problem with IS GREATER THAN OR EQUAL TO. I have tried a dozen variations for this IF statement to work with IS GREATER THAN OR EQUAL TO. My code below WORKS. array=( $( /usr/bin/sar -q 1 30 |grep Average |awk '{print $2,$3}' ) ) nthreads="${array}" avproc="${array}" if && ; then ... (6 Replies)
Discussion started by: diex
6 Replies

6. Shell Programming and Scripting

replacing numbers greater than 0 with 1

I have some ASCII files containing numerous numbers. What I'd like to do is replace all numbers greater than 0 with 1. Examples of the numbers include: - 000011 and 000042 Thanks (4 Replies)
Discussion started by: vrms
4 Replies

7. Shell Programming and Scripting

AWK greater than?

Sorry for such a basic question, but I have spent hours trying to work this out! I need an awk command (or similar) that will look at a text file and output to the screen if the 4th column of each line has a value greater than or equal to x. data.txt This is the 1 line This is the 2 line This... (6 Replies)
Discussion started by: dlam
6 Replies

8. Shell Programming and Scripting

greater than less than in case

Hi , I want to do the following: i=6 case $i in -lt 10) echo Period=10 ;; -gt 10 && -lt 15) echo Period-15 ;; >15 && <20) echo Period=20 ;; >20 && <30) ... (2 Replies)
Discussion started by: sars
2 Replies

9. Shell Programming and Scripting

AWK greater than 200

I need to grep out usernames with UID's greater than 200 out of the /etc/passwd file for a server migration. It is the third field however I am not sure to to accomplish this. I tried to search the forums but did not seem to find an answer (might have over looked it). Any help would be... (2 Replies)
Discussion started by: insania
2 Replies

10. Shell Programming and Scripting

Greater Than

Hello every one! I need a little help. I would like to know if there is someway I can use a "greater than" condition in a shell script. #!/usr/bin/sh _curTime=`date +%H%M` if && then echo "$_curTime" fi I know that "<" and ">" is to input and output to a file I just wanted... (2 Replies)
Discussion started by: Lem2003
2 Replies
Login or Register to Ask a Question