let is an alternative to expr for doing mathematical calculations. It is part of the posix shell and is similiar to the C programming statement e.g.

 let $TOTAL=$TOTAL+1

will add one to $TOTAL This can be alternatively expressed as

(( $TOTAL = $TOTAL + 1 ))

To speed up the arithmetic calculation you can specify that $TOTAL is a number. This is done as follows:

 typset -i TOTAL=10

Another use of typeset is to emulate the substring function found in other languages. e.g.

 typeset -L4 var1="12345678" will set var1 to 1234
 typeset -R4 var2="12345678" will set var2 to 5678

The string 12345678 can be replaced by a variable.

Recent Changes

Contribute to this wiki

Why not help others by sharing your knowledge? Contribute something to this wiki and join out hall of fame!
Contact us for a user name and password