Hacker News new | past | comments | ask | show | jobs | submit login
Shell Has a Forth-Like Quality (2017) (oilshell.org)
31 points by rrampage 9 months ago | hide | past | favorite | 3 comments



from the linked art of programming[0]

> Bernstein chaining is a specialized security-wrapper technique invented by Daniel J. Bernstein, who has used it in a number of his packages. Conceptually, a Bernstein chain is like a pipeline, but each successive stage replaces the previous one rather than running concurrently with it.

I'm impressed shell does this! and have my own function to add to the list of "Commands that Compose." dryrun[1]: when prefixed on a shell command, it echos the command if DRYRUN is set otherwise runs it normally. I pipe that to drytee[2] if the command's modifying files. I like it as a more deliberate (and safer) alternative to 'set -x' for debugging shell scripts.

   for f in in/*; do
     args=($(complicated_code $f))
     dryrun long_procces $f "${args[@]}" | drytee out/${f//*\//}
   end
[0]<http://www.catb.org/%7Eesr/writings/taoup/html/ch06s06.html>

[1] https://github.com/lncd/lncdtools/blob/master/dryrun

[2] https://github.com/lncd/lncdtools/blob/master/drytee


Another scripting language that does this chaining is Execline (https://skarnet.org/software/execline/). I like using it in containers (in combination with s6).


  retry() {
    local n=$1
    shift
    for i in $(seq $n); do
      "$@"
    done
  }
This is not a retry function, it's a "run a function 5 times" function. Retry would check the outcome of the operation, and only for failed cases would run it additional times. It is definitely possible in bash, it's just a few more lines.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: