5 ms·
As others have replied to you, I think you misunderstand what side effects & IO are. Imagine a "normal" shell type chain: ps -ef | grep 'elephant' | sort
by deckiedan 13y ago
As others have replied to you, I think you misunderstand what side effects & IO are.
Imagine a "normal" shell type chain:
ps -ef | grep 'elephant' | sort -nk2 >> logfile.txt
neither `grep`, nor `sort` should have any side effects, and if they do, then you have potential for weird bugs later on. (imagine your / is mounted read only, and sort has a side effect of writing everything to a temp file. now suddenly this otherwise sane looking chain stops working).
In the command, you have a single input, and a single output (which has a specific mode, append). Those are the only IO functions which you've specified, but you have no guarantee that anything else will not make a mess of things.
The dream for "pure functional" shell scripting would be where the side effects are more obvious, and controllable, not to eliminate them.
- yongjik 13y agoExcept that usually grep and sort can read files, or entire directories, which is considered a "side effect" in Haskell. (Not to mention checking locales to decide how to sort, checking if the output is terminal so that we can add colors, but only if the environment variable says so, and on, and on...)
- joeyh 13y agoSort does have the side effect of writing to a temp file, when the input to be sorted is large. :)