Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing variables

Status
Not open for further replies.

ianholmes

Programmer
Mar 24, 2001
61
GB
Hi
I have 2 variables in my shell script :-
$var1 and $var2
I know that they are the same length.
I don't know what that length is.
How go I compare them, ignoring the last character in both ?
 
length of a variable is obtained with #
so.....
var1len=${#var1}-1
var2len=${#var2}-1

HTH ;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
I obviously didn't explain the situation well enough.

If variable1 is ABCDx and variable 2 is ABCDy, I need to match them.
Similarly with XYa and XYb.
 
#!/bin/ksh

a='ABCDx'
b='ABCDy'


a1=${a%?}
b1=${b%?}

#echo "a1->[${a1}] b1->[${b1}]"

if [ "${a%?}" = "${b%?}" ] ; then
echo "SAME"
else
echo "DIFF"
fi;
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top