Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

comparison operators in sh script

Posted on 2004-10-07
1
Medium Priority
?
1,306 Views
Last Modified: 2013-12-26
I have a shell script, written in Bourne shell:

#!/bin/sh

and I want to check if a variable is equal or not equal to something.  For example, I tried using:

if [[ $STATUS = "BUILT" ]] only seems to work with Korn shell
if [[ $STATUS -eq "BUILT" ]] only seems to work with Bash shell

So what are the comparison operators for Bourne shell, preferably is equal to or not equal to?

0
Comment
Question by:cirruslogic
1 Comment
 
LVL 48

Accepted Solution

by:
Tintin earned 200 total points
ID: 12253262
In bourne shell (and all bourne like shells, ie: ksh, bash etc)

you use

= for string equality
-eq for numeric equality
-lt less than
-gt greater than

and many others.

man test

eg:

if [ $STATUS = BUILT ]

or if STATUS is numeric

if [ $STATUS -eq 0 ]
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question