Copied from the readme:


cosh is a concatenative command-line shell.

Why?

Basic shell operations like ls, ps, stat, and so on are implemented as functions that return first-class values, as opposed to relying on executables that return text streams. This makes working with the results simpler:

  • Find file paths matching a string, and search those files for data

sh:

find . -iname '*test*' -print0 | xargs -0 grep data

cosh:

lsr; [test m] grep; [f<; [data m] grep] map
  • Find all processes using more than 500M of memory:

sh:

ps --no-headers aux | awk '$6>500000'

cosh:

ps; [mem get; 1000 1000 *; 500 *; >] grep

A small set of versatile primitives means that less needs to be remembered when compared with typical shells (see e.g. the various flags for cut(1)), though some commands may be longer as a result:

  • Get the second and third columns from each row of a CSV file:

sh:

cut -d, -f2,3 test-data/csv

cosh:

test-data/csv f<; [chomp; , split; (1 2) get] map
  • Sort files by modification time:

sh:

ls -tr

cosh:

ls; [[stat; mtime get] 2 apply; <=>] sortp

Arithmetical operators and XML/JSON/CSV encoding/decoding functions reduce the number of times that it becomes necessary to use a more full-featured programming language or a third-party executable:

  • Increment floating-point numbers in file:

sh:

sed 's/$/+10/' nums | bc

cosh:

nums f<; [chomp; 10 +] map
  • Get the first value from the “zxcv” array member of a JSON file:

sh:

jq .zxcv[0] test-data/json2

cosh:

test-data/json2 f<; from-json; zxcv get; 0 get

It also integrates with external executable calls, where that is necessary:

  • Print certificate data:

bash:

for i in `find . -iname '*.pem'`; do openssl x509 -in $i -text -noout; done

cosh:

lsr; [pem$ m] grep; [{openssl x509 -in {} -text -noout}] map;

See the full documentation for more details.