Solved

comparison operators in sh script

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
if loop error 4 77
iSeries DB2 Query 2 84
string initialization in java 11 103
ffmpeg - "rtsp://...... Operation not permitted" 4 69
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

22 Experts available now in Live!

Get 1:1 Help Now