Re:Interesting commands for the Linux shell
by TorKlingberg on Thursday September 14, 2017 @06:50AM
(#15246653)
I know whatever < file.txt is slightly more efficient, but there is value is keeping things going left to right with pipes in between. It makes it easy to insert a grep or sort, or swap out a part.
[ Parent
| on HN ]
Re:Interesting commands for the Linux shell
by veddan on Thursday September 14, 2017 @07:09AM
(#15246752)
<file.txt grep foo | sort
Re:Interesting commands for the Linux shell
by BenjiWiebe on Thursday September 14, 2017 @11:28AM
(#15248997)
Ok, if that actually works, that's amazing. Wow.
Re:Interesting commands for the Linux shell
by vram22 on Thursday September 14, 2017 @01:02PM
(#15249991)
It works because of the general principle that I mentioned here:
https://news.ycombinator.com/item?id=15249370
The shell (not the command) is the one expanding those metacharacters, so (within limits), in:
cmd < file
or
< file cmd
where you put that piece (< file) on the line does not matter, because the actual command cmd never sees the redirection at all - it is done [1] by the time the command starts. The cmd command will only see the command line arguments (other than redirections) and options (arguments that start with a dash). Even expansion of $ and other sigils (unless quoted) happens before the command starts.
[1] I.e. the shell and kernel set up the standard input of the command to be connected to the file opened for reading (in the case of < file).