Solved

comparison operators in sh script

Posted on 2004-10-07
1
1,293 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 50 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

685 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