3 ms·
I've used *nix for ~15 years and never used a named pipe or process substitution before. Great to know about!
by mhax 12y ago
I've used *nix for ~15 years and never used a named pipe or process substitution before. Great to know about!
- a3n 12y agoNamed pipes have been rare for me, but simple process substitution is every day. Very often I do something like this in quick succession. Command line editing makes this trivial. $ find . -name "*blarg*.cpp" # Some output that looks like what I'm looking for. # Run the same find again in a process, and grep for something. $ grep -i "blooey" $(find . -name "*blarg*.cpp") # Yep, those are the files I'm looking for, so dig in. # Note the additional -l in grep, and the nested processes. $ vim $(grep -il "blooey" $(find . -name "*blarg*.cpp"))
- icebraining 12y agoThat's actually command substitution, not process substitution :)
- jbnicolai 12y agoYou could just use a pipe here though, which would also make it more easy to read. e.g.: $ find . -name '*blarg*.cpp' | grep -li blooey | vi -
- icebraining 12y agoYour version searches for blooey in the filenames, not in the files themselves.
- reitanqild 12y agoAnd, to try to be helpful, - seems it lacks an xargs (or similar construct)
- a3n 12y agoI used to do it something like that, but I find it personally easier to understand the way I described it and evolved into that. I also like what I'm ultimately doing (vim/vi in this case) to be over on the left: edit whatever this mess on the right produces.
- deleted 12y ago[deleted]
- lazyjones 12y ago> Command line editing makes this trivial. I'm lazy, so I typically do this (2nd step) to avoid the extra key strokes necessary for editing: $ grep -i "blooey" $(!!) Also very useful for avoiding editing in order to do something else with the same argument as in the previous command: !$, i.e.: $ foo myfile $ bla !$
- tne 12y agoSame here, except I typically use $(!!) to re-run the previous command. I find it faster than command-line editing. $ find . -name "*blarg*.cpp" $ grep -i "blooey" $(!!) $ vim $(!! -l) Granted, you can only append new arguments and using the other ! commands will often be less practical than editing. Still, it's amazing how frequently this is sufficient. I've always thought it'd be nice if there was a `set` option or something similar that would make bash record command lines and cache output automatically in implicit variables, so that it doesn't re-run the commands. The semantics are definitely different and you wouldn't want this enabled at all times, but for certain kinds of sessions it would be very handy. EDIT: lazyjones beat me to it.
- vog 12y agoSince "!!" are replaced when you hit the "up" arrow key (i.e. jump to previous command), you can go really wild with them: https://oeis.org/A228162 https://oeis.org/A228162
- masklinn 12y agoBeware though, process substitution is not POSIX and not supported in all shells. It isn't in pdksh or ash/dash for instance. It's a ksh93 extension adopted by bash and zsh.