1. 17
    1. 9

      Ah, I’m glad I could have my morning reminder that shells are really great for starting programs written in sane programming languages.

      1. 4

        Another of those reasons that I hate seeing any bash scripts that do such magic

        1. 4

          Since it’s mentioned in the article itself, the way time works is also somewhat counter-intuitive - it modifies the entire pipeline rather than an individual command - but makes sense if you think about it: when running time echo | echo you probably want to know how much time the entire pipeline takes, rather than the first command.

          What this also means that bash’s time doesn’t support echo | time echo. However, if you do something like echo | time echo, it probably will work, because time is also frequently available as an external command.

          I hope it’s not too off-topic to plug Elvish, which doesn’t have the obscure ! stuff, and where time works in the most logical way: it’s a builtin command rather than part of the syntax, and it takes a lambda. You can write time { echo | echo } or echo | time { echo } and they both do exactly what you would expect. (And if you want to benchmark some code multiple times, just use benchmark instead.)

          In fact time is my go-to example for why shells actually should have lambdas, and not having them ultimately leads to some very weird and surprising semantics!

          1. 2

            The questions assume that you know what ! syntax does in Bash, and that the only background you need is where that symbol can be used according to the manual. But I have no idea what ! is supposed to do, so it feels pointless to guess where it could be written.

            1. 2

              It’s usually used as part of if ! whatever; then ...; fi where it seems obvious what it does if you know that true is command success (0 exit code) and false is non-zero exit codes. The shell being what it is, if conditions are just commands and can be run on their own as shown in the quiz.