Date: Fri, 27 Sep 2002 16:24:59 +0200 (CEST) From: Oliver Fromme <olli@secnetix.de> To: freebsd-questions@FreeBSD.ORG Subject: Re: no xargs -i flag Message-ID: <200209271424.g8REOxVD040291@lurza.secnetix.de> In-Reply-To: <20020924184251.J64949-100000@earl-grey.cloud9.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Peter Leftwich <Hostmaster@video2video.com> wrote: > I'm surprised that xargs has no flag for interactive mode (-i) so that the > command line will be echoed to the terminal asking [y/n/!] where y means yes > proceed and n means no stop now and ! would mean answer y to all remaining > promptings. Normally there is not much use for such an option, that's why nobody has bothered to implement it. (Well, there is -t, but it only echoes the command line, but doesn't ask for confitmation.) Typically, xargs is used when there are a lot of files (or an unknown number of files, which could also mean a lot). So the command line echoed at you would probably be larger than your terminal window. When there are only a small number of files, there is not much of a point in using xargs. > If the command passed to xargs *includes* something like "mv -i" will xargs > run interactively? No, but mv will. :-) > Sort of unrelated, but what if you wanted to pass something like `grep -i > something each_xarged_file | mail -s output $USER` as opposed to just `grep > -i something each_xarged_file`? No special handling necessary, it'll work just fine. > That is, how do you let xargs know where > to put the filename, if not at the end of the command line? xargs doesn't see your command line at all. It only sees the arguments passed to it by your shell. For example: $ find /foo -type f | xargs grep whatever | mail -s bar $USER In this case, your shell creates three processes which are connected by pipes (find, xargs and mail). The arguments passed to the xargs process are "grep" and "whatever". The xargs process doesn't see anything else. It doesn't even know that it's piping into another process (which happens to be mail). xargs just takes its arguments and (after processing any options) executes it as a command. The standard ouput of that command (grep) is passed to the standard output of the xargs process itself. > It isn't clear > from the manpage or examples I've browsed. Thanks. The problem is that there are several different mechanisms involved. The handling of pipes, processes and the parsing of command line arguments is explained in the manual page of your shell, for example the sh(1) manpage. The way xargs constructs commands from its arguments and stdin is detailed in the xargs(1) manpage. You have to put it all together in order to understand how it works. Regards Oliver -- Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München Any opinions expressed in this message may be personal to the author and may not necessarily reflect the opinions of secnetix in any way. "All that we see or seem is just a dream within a dream" (E. A. Poe) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209271424.g8REOxVD040291>