Scripting with zsh
The main purpose of the zsh shell was to provide an advanced programming environment for shell programmers. With that in mind, it's no surprise that the zsh shell offers many features that make shell scripting easier.
Mathematical operations
As you would expect, the zsh shell allows you to perform mathematical functions with ease. In the past, the Korn shell has led the way in supporting mathematical operations by providing support for floating-point numbers. The zsh shell has full support for floating-point numbers in all its mathematical operations!
Performing calculations
The zsh shell supports two methods for performing mathematical operations:
- The
let
command - Double parentheses
When you use the let
command, you should enclose the operation in double quotation marks to allow for spaces:
% let value1=" 4 * 5.1 / 3.2 "
% echo $value1
6.3750000000
%
Be careful, using floating point numbers may introduce a precision problem. To solve this, it&apos...