Comment by panzi

7 days ago

Why would you implement system() at all?

parse commands from config file? command-line arguments for hooks?

https://news.ycombinator.com/item?id=44239036

  • I understand that it is convenient for running small snippets like that, but I don't really think it's worth the risk. And putting it into a config file is different, IMO. You don't get tempted to do some bad string interpolation there, because you can't, unless the config file format has support for that, but then I criticize that. If you need to pass things to such a snipped do it via environment variables or standard IO, not string interpolation.

    If you say you don't make such mistakes: Yeah, but people do. People that write the code that runs on your system.

    • But if you want a command-line option for hook, what are the alternatives?

      Force user to always create a wrapper script? that's just extra annoyance and if user is bad at quoting, they'll have the same problems with a script

      Disable hooks at all? that's bad functionality regression

      Ask for multiple arguments? this makes command-line parsing much more awkward.. I have not seen any good solutions for that.

      (The only exception is writing a command wrapper that takes exactly 1 user command, like "timeout" or "xargs".. but those already using argument vector instead of parsing)

      6 replies →

Because I don't want to implement a shell???

  • If you want to run a shell script, run a shell script. I.e. a text file with the executable bit set and a shebang. If you want to generate a shell script on the fly to then run it, take a step back and think about what you're doing.