diff --git a/include/functions b/include/functions index 4f3b15a9..e0149b45 100644 --- a/include/functions +++ b/include/functions @@ -43,6 +43,7 @@ # DisplayManual Output text to screen without any layout # DisplayToolTip Show a tip for improving usage of the tool # DisplayWarning Show a clear warning on screen +# Equals Compares two strings # ExitClean Stop the program (cleanly), with exit code 0 # ExitCustom Stop the program (cleanly), with custom exit code # ExitFatal Stop the program (cleanly), with exit code 1 @@ -627,6 +628,27 @@ } + ################################################################################ + # Name : Equals() + # Description : Compare two strings + # + # Returns : (0 - True, 1 - False) + # Usage : if Equals "${MYDIR}" "/etc"; then echo "Found"; else "Not found"; fi + ################################################################################ + + Equals() { + RETVAL=1 + if [ $# -ne 2 ]; then ReportException "Equals" "Incorrect number of arguments for $0 function"; fi + + # Strip any strange control characters + INPUT1=$(echo $1 | tr -d '[:cntrl:]<>' | ${SEDBINARY} 's/__space__/ /g' | ${SEDBINARY} 's/:space:/ /g') + INPUT2=$(echo $2 | tr -d '[:cntrl:]<>' | ${SEDBINARY} 's/__space__/ /g' | ${SEDBINARY} 's/:space:/ /g') + if [ "${INPUT1}" = "${INPUT2}" ]; then RETVAL=0; fi + + return ${RETVAL} + } + + ################################################################################ # Name : ExitClean() # Description : Perform a normal exit of the program, and clean up resources