2018-04-05
___P_l_a_n__9__n_u_g_g_e_t_s__-__T_h_e__r_c__s_h_e_l_l_______________

Today I want to show you a real gem that has been developed by Tom
Duff[0]: The rc shell.  It is the only shell (by default) available
for plan 9. It features a bourne shell like syntax but offers a much
cleaner syntax.


I like it a lot due to:

  * Variables are list of strings by default and subscriptable: You
  can write things like '''athing=(foo bar baz); echo $athing(1 1 3
  2)''' which gives 'foo foo baz bar'.

  * String contatenation is (almost) explicit: You use the caret ^
  operator.

  * You need to enclose everything containing spaces in ''. You
  escape a ' by writing ''. No backslash hell.

  * Pattern matching on variables with ~

  * switch statements look like C, but work without break. Funnily
  this means that Duff's device does not work in this shell :)

  * Pipeline branching: You can feed the output of separate commands
  into pipes with '''<{command}''' (or '''>{command}''')

  * Sane syntax for I/O redirection: You give it the file descriptor
  number: '''make [2]> warnings.log [1]>build.log'''
    Or grep the stderr with '''strace foo |[2] grep open'''

  * Some of the functions you have gotten attached to are missing
  but can be replaced easily. For example there is no read builtin.
  But here's the replacement:
'''rc
     fn read{
        $1=‘{awk ’{print;exit}’}
     }
'''

All this and more can be found in the rc paper[1] describing the
whole syntax. I think the saner quoting rules make scripts less error
prone and the pipe syntax enables easy scripting with networking
tools like ii[2]. There is a port to modern unix available[3] just
remember to pass the '--enable-edit=' option to configure. Yes, it
uses autotools. Oh the irony...

___References________________________________________________________

[0]: gopher://gopherpedia.com:70/0/Tom Duff
[1]: http://doc.cat-v.org/plan_9/4th_edition/papers/rc
[2]: https://tools.suckless.org/ii/
[3]: https://github.com/rakitzis/rc