top of page
Streams and objects

The ls operator lists files, like any Linux shell. But there are important differences. The Linux ls executable prints strings describing files, either multiple file names per line; or, if you specify the -l flag, then one file per line, with each line including file attributes such as mode, modification time, owner, group, and others. I.e., the printing and formatting logic is part of the ls executable.

By contrast, marcel's ls operator generates a stream of File objects, and has no responsibility for printing or formatting -- if you run help ls you will see no such options.

The stream of File objects generated by ls can be passed to the output operator, write:

M 0.18.3 jao@loon ~/git/marcel/marcel$ ls object | write
drwxr-xr-x   jao    jao        4096   2023 Sep 10 12:32:29   .
-rw-r--r--   jao    jao         652   2020 May 10 15:41:11   __init__.py
drwxrwxr-x   jao    jao        4096   2023 Oct 25 17:30:55   __pycache__
-rw-rw-r--   jao    jao        3120   2023 Sep 07 20:53:42   cluster.py
-rw-rw-r--   jao    jao        4793   2023 Oct 25 13:53:07   color.py
-rw-rw-r--   jao    jao        2660   2020 Nov 19 14:12:20   db.py
-rw-r--r--   jao    jao        1436   2022 Nov 29 11:33:51   error.py
-rw-rw-r--   jao    jao        8763   2023 Oct 25 13:53:07   file.py
-rw-r--r--   jao    jao        1707   2020 Aug 11 19:24:19   historyrecord.py
-rw-r--r--   jao    jao        2548   2020 Nov 06 10:28:57   process.py
-rw-r--r--   jao    jao         856   2020 Aug 11 19:24:19   renderable.py

The net effect is a listing very much like what you would see by running ls -l from bash.

You can almost always omit explicitly using the write operator. Marcel appends write to your command line, if you don't specify it yourself. So you can get the same listing of files by just writing ls. You do need to specify write explicitly if you want to write to a file, instead of to the console, or to control formatting. For example, to save the ls result in /tmp/files you could do the following:

M 0.18.3 jao@loon ~/git/marcel/marcel$ ls object | write /tmp/files

There is no output to the console, because the output from ls was written to /tmp/files. (The same command could also be written as ls object > /tmp/files, as in bash.)

bottom of page