From owner-freebsd-questions@FreeBSD.ORG Fri Sep 8 14:23:26 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BDDAF16A4DA for ; Fri, 8 Sep 2006 14:23:26 +0000 (UTC) (envelope-from dking@ketralnis.com) Received: from ketralnis.com (melchoir.ketralnis.com [68.183.67.83]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6A27A43D4C for ; Fri, 8 Sep 2006 14:23:26 +0000 (GMT) (envelope-from dking@ketralnis.com) Received: from [10.0.1.239] (ayla.wifi.int.ketralnis.com [10.0.1.239]) (authenticated bits=0) by ketralnis.com (8.13.6/8.13.6) with ESMTP id k88ENPBk057851 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NO); Fri, 8 Sep 2006 07:23:25 -0700 (PDT) (envelope-from dking@ketralnis.com) In-Reply-To: <45016BBC.8080803@kth.se> References: <45016BBC.8080803@kth.se> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: David King Date: Fri, 8 Sep 2006 07:23:19 -0700 To: freebsd-questions@freebsd.org X-Mailer: Apple Mail (2.752.2) Cc: lassee@kth.se Subject: Re: How do I give 2 parameters to programs in an unix enviroment? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Sep 2006 14:23:26 -0000 Here's an example using zsh (I assume it's the same using bash, but different using tcsh or sh): diff <(find /usr/local -type f | sort) <(for each in /var/db/pkg/*/ +CONTENTS; do grep -v '^@' $each; done | sort) This does a diff(1) of what /var/db/pkg says that /usr/local should look like, and what it *really* looks like (note that it would need some tuning in order to actually be useful, but you get the idea) This uses the <() operator. What the <() operator does is create a named pipe in /tmp, execute the commands contained in the parenthesis in a subshell, and connect the stdout of the subshell into that named pipe. So it's sort of like using temp files, but you don't have to clean up after yourself. There's another, similar operator that does force it to use temp files, but I can never remember what it is :) Check the manpages for your shell Note that not all programs support using named pipes instead of files, since they expect to be able to do things like rewind the current position in the file descriptor. diff(1) looks to support it okay, though. A simplified version of your example would look like this: diff <(cat foo) <(cat bar) On 08 Sep 2006, at 06:10, Lasse Edlund wrote: > If I have two files "foo" and "bar" and try to run diff on them I > write: > $diff foo bar > I can also write > $cat foo | diff - bar > But how do I give a program two (2) commands? not only to diff > but to any program that wants double input... > I wanna do > $cat foo | cat bar | diff - - > especially with echo commands that would be handy so I dont have to > create files!