Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you really prefer to see things in order then

    <foo sort | ...
is an alternative to

    cat foo | sort | ...
though I wouldn't particularly recommend it. Instead the overhead of cat(1) should be omitted and it written in the normally accepted form of

    sort foo | ...
Providing a filename rather than re-directing stdin allows the program more choice over its method of access.


I find the "cat foo | .." in the beginning and "| cat > bar" at the end form more regular.

While iterating on a command line, it keeps things uniform, rather than switching between "sort foo" and "tai64nlocal < foo" and "ffmpeg -i foo", by which I mean: different programs take their input in different ways. You can normalize by making each take standard input, and feed the chain with a "cat".


I can understand liking the regularity but in production code or web examples it shouldn't be done because of the overhead. However, your example doesn't make sense.

If sort, tai64nlocal, and ffmpeg are all happy to read stdin so you can do

    cat foo | sort ...
    cat foo | tai64nlocal ...
    cat foo | ffmpeg ...
then they can all have their stdin redirected instead by the shell:

    <foo sort ...
Similarly with stdout:

    ... | sort | cat >foo
becomes

    ... | sort >foo
In both cases regularity of having the filename at the start and end is preserved.




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

Search: