Command Piping

Piping is used to chain multiple commands and refer to the previous command's result value in the current command. Every command's result will be in a tabular form where column headers and rows with their corresponding column values are displayed.

The "|" (pipe) operator is used to chain multiple commands.

The "$" symbol is used to refer to the previous command's result columns.

Sample command

Copiedzmail:>account list
+---------------------+--------------+--------------------------+
| Account Id          | Display Name | Email Address            |
+---------------------+--------------+--------------------------+
| 8*****************2 | johnm        | johnm@zylkertraining.com |
+---------------------+--------------+--------------------------+

In the above result, the first row are the column headers. Say, you want to use the Account Id header values in folders list command for the --account option. 
Then you can perform the command mentioned below:

To use Account Id header values in folders list command

Copiedzmail:>account list | folders list --account "$Account Id"

Output

Copied+---------------------+------------------+--------------------------+---------------------+
| Folder Id           | Folder Name      | Path                     | Previous Folder     |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************2 | Inbox            | /Inbox                   | -                   |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************2 | Drafts           | /Drafts                  | 8*****************2 |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************2 | Templates        | /Templates               | 8*****************2 |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************2 | Snoozed          | /Snoozed                 | 8*****************2 |

In the above command, you have used the "|" (pipe) operator for chaining the folders list command after the account list. In addition to that, you also referred to the "Account Id" column of the previous command's result.

First, the CLI tool will partition the command based on the pipe operator. Then, while executing each command, the tool will check whether a reference operator ($) is used in the command.

If the $ operator is used, then the tool will check for column values with that referred name in the previous command's result. And for every row in the previous command's result, its column value will be replaced in the referred parts of the command and then executed.

So in this case, the account list command will produce a result with 1 row in it.
Then, while running the folders list --account "$Account Id" command, the tool will notice the reference operator used and execute the folders list command for each row in the previous command result by replacing the referenced places with that row data.

Below is the execution flow of the folders list command,

Folders list command

Copiedzmail:>folders list --account  8*****************2 
+---------------------+------------------+--------------------------+---------------------+
| Folder Id           | Folder Name      | Path                     | Previous Folder     |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************2 | Inbox            | /Inbox                   | -                   |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************2 | Drafts           | /Drafts                  | 8*****************2 |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************3 | Templates        | /Templates               | 8*****************8 |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************2 | Snoozed          | /Snoozed                 | 8*****************7 |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************2 | Sent             | /Sent                    | 8*****************2 |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************2 | Spam             | /Spam                    | 8*****************2 |
+---------------------+------------------+--------------------------+---------------------+
| 8*****************2 | Trash            | /Trash                   | 8*****************24 |
+---------------------+------------------+--------------------------+---------------------+

The tool will print only the last command's result. So the intermediate command's result will be ignored to print to the display.