Solved

comparison operators in sh script

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
string initialization in java 11 115
fizzArray  challenge 1 95
changeXy challenge 13 88
Path of Workbook 3 86
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 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 shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

840 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