Translate

Archives

Bash and Korn Shell Let Keyword

Recently a colleague of mine recommended using the let keyword in shell scripts to perform arithmetic evaluation. That prompted me to write this post about the let keyword. Here is what the bash manpage says about the let keyword: let arg [arg …] Each arg is an arithmetic expression to be evaluated. If the last arg evaluates to 0, let returns 1; 0 is returned otherwise. And here is a simple example of it’s use: $ a=2 $ b=5 $ let c=$a+$b $ echo $c 7 $ let c=$a + $b $ echo $c 2 As you can see from