1. 7
  1.  

  2. 2

    The title is a little misleading as Oil is yet another shell, so it’s not so much “improving a Bash script using Oil” as it is “replacing a Bash script with an Oil script”.

    1. 2

      That’s true, but you can also use Oil just to improve a bash script… just parsing or running it with Oil may make the script more comprehensible, and less reliant on the vagaries of bash (which do change from version to version). Example with a Lisp in bash:

      http://www.oilshell.org/blog/2020/06/release-0.8.pre6.html#patch-to-run-the-mal-lisp

    2. 2

      As always, I compare other shells to my Next Generation Shell.

      $ cat p.ngs 
      #!/usr/bin/env ngs
      script = fetch("package.json").scripts[ARGV[0]]
      log: bash -c $script
      

      Output:

      ./p.ngs 'say hello'
      [LOG 2020-09-30 08:17:45 IDT] Running command: bash -c echo\ \"Hello\ world\!\"
      Hello world!
      

      Similarities:

      • No variable expansion bomb. $script would be "$script" in bash
      • Data structures
      • JSON support

      Differences:

      • No bash compatibility in NGS (hence bash -c)
      • Programming language less similar to bash

      Extras:

      • log: prefix before command. It is common to want to print the command before execution so it’s in. The language facility is supporting SOMETHING: syntax before commands. The next level is the log itself.
      • fetch() knows it’s JSON by looking at extension and you don’t have to specify