Using expr in scripts
Using expr in scripts As many scriptors know (and probably hate) Bourne shell doesnt have inbuilt arithmetic capabilities so one has to resort to expr for calculations, the most famous maybe being the loop increase: i=0 while [ $i -lt 10 ] ; do ... i=`expr $i + 1` done expr has more operators though than just the basic arithmetics and I dont see them used very frequently, I think I havent used them at all so - stumbling upon it accidentally - I thought Id play with it a little to get a better understanding and heres the result. The match operator (string comparison with regular expressions) The operator to compare a string to a regular expression is the colon (:) . expr will return the number of bytes matched (the curious might look into the xpg4 version of expr which returns the number of characters matched). Also important: the regular expression always starts to compare at the beginning of the string so as if one would have used ^ . A few examples. f="/a/c"...