bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: finding the index at which two strings differ


From: Dave B
Subject: Re: finding the index at which two strings differ
Date: Tue, 06 May 2008 22:33:42 +0200

On Tuesday 6 May 2008 21:29, Bob Proulx wrote:

> I can't think of any way to do this natively in bash

Well, there's a loop solution, but it's a bit awkward:

a=help; b=hello; i=0
while [ $i -le $((${#a}-1)) ] && [ $i -le $((${#b}-1)) ]; do
  if [ "${a:${i}:1}" = "${b:${i}:1}" ]; then 
    i=$((i+1))
  else 
    break
  fi
done
echo $((i+1))

-- 
D.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]