Home > Back-end >  Write a backlink in regular terms to determine the equality of two numbers
Write a backlink in regular terms to determine the equality of two numbers

Time:04-30

Please tell, how it is possible to execute it For example the person entered 24 and 24 appeared on the screen "ok", on the contrary when entered 24 and 23 person received "not ok"? I tried as follows:

#!/bin/bash

read a
read b
if <("$a" == "$b")>.*<\1>
then
   echo ok
else
   echo not ok
fi

CodePudding user response:

You only need a direct variable comparison:

#!/bin/bash

read a
read b
if [ "$a" -eq "$b" ];
then
   echo ok
else
   echo not ok
fi

enter image description here

Back-reference is for complex requirements like this:

https://javascript.info/regexp-backreferences

Also regex is not used to compare different values. It is used to compare the incoming value with a predefined, expected or desired pattern like this example in which the expected pattern is a mail and the incoming value could be any string

if [[ "$1" =~ ^[a-zA-Z0-9._% -] @[a-zA-Z0-9.-] \.[a-zA-Z]{2,4}$ ]]
then
    echo "Email address $email is valid."
    break
else
    echo "Email address $email is invalid."
fi
  • Related