An enhanced, but compact shell-command processor

2018-10-09 @Technology

Not long ago I devised an enhanced command processor in shell script, and called it exec-cmd. It might be the shortest (60-70 line) most-handy utility I had written, although shell script line count is not the clearest indicator of complexity, considering much reference to external text-processing utilities.

I wanted something to

  1. Be less verbose than shell functions.
  2. Be more expressive than shell aliases.
  3. Provide less verbose aliases, defined together with the main function.
  4. Feature inline named parameters, without explicit declarations or additional variable setting.
  5. Automatically display appropriate hints for missing parameters. This was one of the key motivators. I can see a Lisp macro very natural to this purpose, unlike basic shell script, requiring an awkward wrapper (which exec-cmd essentially carries out).
  6. Enable the invocation of other defined routines.
  7. Encapsulate all routines in a command file external to the shell script configuration, with autocompletion support.
  8. Be immediately interpreted like an external script.
  9. Display command help from an optional help file.

The processor utilizes basic shell script with two specialized constructs:

  1. !!param to indicate an inline parameter.
  2. %self% to reference other command defined in the processor.

The above are reconfigurable either inside the executable or an external ~/.exec-cmd.rc.

I found exec-cmd perfect for small shell-like applications without having to declare functions, explicitly check for passed parameters, or create external scripts.

You can find a sample command file named commands in the repository, much of which contains routines I use on a daily basis.

Questions, comments? Connect.