[clug] fun with bash: <(cmd) ==> like $(cmd) but attached to a named pipe as stdin

steve jenkin sjenkin at canb.auug.org.au
Fri Dec 12 15:29:11 MST 2014


This article showed me something new & useful in bash - run a command and redirect output to or from a named pipe. <(cmd) and >(cmd).

$(cmd) and `cmd` do in-place replacement of the output of a command - this adds a new variation, avoiding catching output in temp files.

<http://www.linuxjournal.com/article/2156?page=0,1>

Examples from article:

> cmp <(ls /dir1) <(ls /dir2)

> ls | tee >(grep foo | wc >foo.count) \
>          >(grep bar | wc >bar.count) \
>          | grep baz | wc >baz.count


=====
My recent use… pull the (mac) ‘port’ name out of two files and find differences - without intermediate files.

src steve$ i=/Users/steve/macports.10.10.1_1.installed
src steve$ j=/Users/steve/macports.10.10.1_2.installed 

src steve$ diff <(grep '(active)' $i | sed 's/^  //‘ | cut -d' ' -f1) <(grep '(active)' $j | sed 's/^  //‘ | cut -d' ' -f1)

43d42
< darwinbuild
72a72
> dyld-headers
227d226
< llvm-gcc42
--
Steve Jenkin, IT Systems and Design 
0412 786 915 (+61 412 786 915)
PO Box 48, Kippax ACT 2615, AUSTRALIA

mailto:sjenkin at canb.auug.org.au http://members.tip.net.au/~sjenkin



More information about the linux mailing list