Solved

comparison operators in sh script

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Shell script to login to remote m/c and execute commands 10 78
format the code in java 6 86
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 74
Excel file not created as expected 7 50
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now