Re: How do I give 2 parameters to programs in an unix enviroment?
On 8 September 2006, at 08: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 - - The entire purpose of cat is to concatenate files (make them output one after another). So, do: cat foo bar | diff - - especially with echo commands that would be handy so I dont have to create files! ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions- [EMAIL PROTECTED] -- hackmiester (Hunter Fuller) svinx yknow when you go to a party, and everyones hooked up except one guy and one girl svinx and so they look at each other like.. do we have to? svinx intel nvidia must be lookin at each other like that right now Phone Voice: +1 251 589 6348 Fax: Call the voice number and ask. Email General chat: [EMAIL PROTECTED] Large attachments: [EMAIL PROTECTED] SPS-related stuff: [EMAIL PROTECTED] IM AIM: hackmiester1337 Skype: hackmiester31337 YIM: hackm1ester Gtalk: hackmiester MSN: [EMAIL PROTECTED] Xfire: hackmiester ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: How do I give 2 parameters to programs in an unix enviroment?
On Mon, 11 Sep 2006, hackmiester (Hunter Fuller) wrote: On 8 September 2006, at 08: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 - - The entire purpose of cat is to concatenate files (make them output one after another). So, do: cat foo bar | diff - - This advice is wrong. To answer the original question: the shell pipe connects the stdout of the first process to the stdin of the second process using a pipe. The stock shells don't have a way of doing what you're after. If you have fdescfs mounted, ksh can do something like what you're after using the syntax: diff (cat foo) (cat bar) zsh supports something similar and can work around the lack of fdescfs. -- jan grant, ISYS, University of Bristol. http://www.bris.ac.uk/ Tel +44 (0)117 3317661 http://ioctl.org/jan/ ( echo ouroboros; cat ) /dev/fd/0 # it's like talking to yourself sometimes ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
How do I give 2 parameters to programs in an unix enviroment?
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! ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: How do I give 2 parameters to programs in an unix enviroment?
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! You don't. Recall that | is the pipe operator, and like in real life, there's one input and one output. Pipes used on the command line are for all intents and purposes unnamed, and you can only build up one pipeline. That's why named pipes were invented, so that you could have multiple pipes and refer to them by name (instead of implicitly). But in your case, using named pipes is really no different than using files. -- Matt Emmerton ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: How do I give 2 parameters to programs in an unix enviroment?
--- Lasse Edlund [EMAIL PROTECTED] 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! ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] diff foo bar is the the way a contruct like (cat foo; cat bar| diff - -) may work but I doubt it because they both are writing to the same STDOUT and so - - is more then likely invalid. (echo random junkola foo) (cat foo bar) or (echo random junkola foo) (cp foo bar) would be just as good. would echo the same thing to two files. I think what you want might be diff `cat foo` `cat bar` which is the the quote on the tilde key. check man eval if I'm using the right quote this will evaluate the command in the ` ` and pass its STDOUT as a parameter. For large files this might fail because of the limitation to the command line length, I'm not certain. the best thing might be look in /etc/rc for the last line which will be something like: echo `date` those are the quotes you want and this is the only way to do what I think you're asking. -brian ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: How do I give 2 parameters to programs in an unix enviroment?
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! ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: How do I give 2 parameters to programs in an unix enviroment?
In the last episode (Sep 08), David King said: 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 Just for the archives, The =() operator puts the output to a temp file and returns the filename to the main command. It has to wait for the subshell to finish before running the main command, though. -- Dan Nelson [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: How do I give 2 parameters to programs in an unix enviroment?
Here's an example using zsh (I assume it's the same using bash, but different using tcsh or sh): [...] This uses the () operator. [...] There's another, similar operator that does force it to use temp files, but I can never remember what it is :) [...] Just for the archives, The =() operator puts the output to a temp file and returns the filename to the main command. It has to wait for the subshell to finish before running the main command, though. Ah, thanks, I'll try to remember that this time :) Note that the =() operator, because it uses regular files, doesn't have the issue that some programs won't know how to deal with it (that is, because they are regular files, they support things like fseek() etc). The downside, as Dan said, is that the entire command line isn't executed until all of the subshells within =() operators complete (so the example I gave could take a long time to have any output). Also note that the =() operator will put its temp files in / tmp by default (unless you set your shell to put them elsewhere), so if you have a command with a lot of output, make sure that your /tmp can take all of it. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]