[Linux-disciples] xargs questions

Adam Rosi-Kessel adam at rosi-kessel.org
Thu Nov 11 08:18:29 EST 2004


On Wed, Nov 10, 2004 at 09:32:13PM -0500, Stephen R Laniel wrote:
> asv '^gnome' |ig upgradeable |sed 's/^\(.*\)\/.*$/\1/' |xargs -i sagit '{}' 
[...]
> If instead I take the output of sed and pipe it through
> "tr '\n' ' '" -- to convert all the newlines to spaces --
> xargs seems to send along a final newline that it shouldn't
> send, which ends up answering 'no' to a question that
> apt-get install asks me. This aborts the installation.
> So: how do I get all the lines output by sed to be processed
> through xargs the way I expect?

There are much easier ways to do this with aptitude.  But let's assume
you don't want to use aptitude.

The easiest fix would just be to include -y in your apt-get options and
then you won't have tho 'no' problem.

Otherwise, I think the reason it's answering 'no' might not be the
newline at the end, but because STDIN has been redirected and it's not
getting control back from the keyboard--once you've started the pipe,
it's there for the whole process.

Note that the '{}' is necessarily linked to -i; you can specify an
arbitrary replacement script after -i, but the default is '{}'.  Without
-i, there is no '{}'.

> I thought the point of xargs was to create commands that
> fit on the command line -- e.g., if there were too many
> upgradeable packages in my problem above, bash would tell
> me that my command line was too long and abort. xargs is
> then essentially a hack to get around a deficiency in bash,
> right? Or no? If that's its job, what is it doing in the
> 'tail -$LINES' command line above?

I'm not sure what it's doing in the tail command above, but the point of
xargs is *not* to create commands that fit on the command line--the point
is to take STDIN and convert it to arguments to a command.  It's
essential glue.
-- 
Adam Rosi-Kessel
http://adam.rosi-kessel.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20041111/7460d14e/attachment-0001.pgp


More information about the Linux-disciples mailing list