5 views

A Simple Bash Script to check whether arithmetic expressions A and B are equal

#!/bin/bash
# (c) 2014 http://www.AskDevOps.org
# bash script -eq (linux bash -eq)
# Checks whether arithmetic expressions A and B are equal.
A=10
B=11
if [ $A -eq $B ] ; then
    echo "$A and $B are equal"
else
    echo "$A and $B are NOT equal"
fi
# This outputs: "10 and 11 are NOT equal"

A=10
B=10
if [ $A -eq $B ] ; then
    echo "$A and $B are equal"
else
    echo "$A and $B are NOT equal"
fi
# This outputs: "10 and 10 are equal"

# One line example
test $A -eq $B && echo "$A and $B are equal" ||  echo "$A and $B are NOT equal"
# prefer the indented code until unless there is a real need for one liner
Nov 20, 2014 by | 5 views
Articles for DevOps Geeks
MobaXterm Customization
CHMOD Explained!
Bash history powerful tips
Ubuntu bash from Windows
..