4 ms·
The first command of the first example is a cat|grep... How can I assume the author is an experienced script writer? In any case, ZX replaces some of the shell
by teo_zero 3y ago
The first command of the first example is a cat|grep... How can I assume the author is an experienced script writer?
In any case, ZX replaces some of the shell's usual quirks with its own different quirks: you have to manually expand * with glob() and ~ with os.homedir(), you can't build commands as strings without repeated calls to push(), etc.
- dspillett 3y ago> example is a cat|grep... How can I assume the author is an experienced script writer? Perhaps because they are writing documentation that can be understood be less experienced script writers as well as themselves, using a very common example seen everywhere? I find "cat full | ..." keeps the left-to-right flow of a command nicely, and is better understood by those less familiar with shell work than prepending "< file " which I've seen cause confusion.⁰ Yes, it is an extra process. Yes this is less efficient, both due to the fork and the extra IPC along the pipe. But even under Windows where spawning a process is massively more costly than other OSs¹, if you are that worried about this bit of inefficiency² then perhaps you have picked the wrong tool for the job in using a shell/script in the first place?³ > with its own different quirks I agree there. Though I can see that for some, starting from already using JS via node, this might be an acceptable trade-off. -- [0] I sometimes also use it in part to wind up the cult of demogification, because they seem to both want to be wound up and deserve to be wound up :-) [1] Complain to MS about that, not me and my script/one-liner. [2] Are you using it in a tight loop? Maybe if you are doing something over thousands of files, but then the resources used by the something likely dwarf the cost of cat into irrelevance. [3] A question that suggests the supplementary: are you an experienced <whatever>?
- teo_zero 3y ago> I find "cat full | ..." keeps the left-to-right flow of a command nicely Sorry, I don't buy it. You don't read files like this: cat file | less And you don't compile C programs like this: cat hello.c | gcc -xc - Actually using less, grep (and even gcc) as filters is more confusing to "those less familiar with shell work".
- dspillett 3y agoFor a single command acting on a file, especially with no other parameters, like your less example, you are right and I wouldn't, though I have seen it often. There is practically no "left-to-right" flow to break. Longer examples is where I would use it. Also not in circumstances where explicitly acting on a file like your GCC example. It is unlikely that GCC will commonly be used as part of a more collect pipeline of commands. Note that I said "I use it", not "I always use it, without fail, no other option makes sense ever". Different tools, different jobs (this is what the Church of Latter Day Demogifiers usual don't accept in this context).