[Linux-disciples] xargs
Adam Kessel
linux-disciples@bostoncoop.net
Thu, 13 Nov 2003 09:39:44 -0800
--4Ckj6UjgE2iN1+kY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Thu, Nov 13, 2003 at 11:23:02AM -0500, Stephen R Laniel wrote:
> dpkg --get-selections '*mozilla*' |igv 'deinstall\|purge' |cut -f1 | xarg=
s sudo apt-get install -t unstable
> That seems to do what I want, but it also seems to be sending along a
> spurious 'n'. Try out that command on your machine and you'll see what I
> mean: it passes along the right set of arguments to 'apt'. Then when apt
> asks whether to continue, it quickly says 'n' and aborts. Any idea why?
It's doing that because you have STDIN redirected to the output from
xargs; apt-get will not accept input from the keyboard, but only from
whatever comes out of your pipe. The first thing apt-get asks you is "Do
you want to continue? [Y/n]" and it can't get input from keyboard.
As a simple experiment, try:
touch abc
echo abc | xargs vim
You'll notice it says=20
Vim: Warning: Input is not from a terminal
Vim will actually still work here, presumably because vim figures it out
and switches STDIN back to console.
One way around this, in your case, would be to use the --yes switch for
apt-get, which answers "yes" to all questions, and thus does not require
keyboard input.
A few other things, though:
* It looks like it would be better to do what you are trying to do with
aptitude, which lets you selective install or upgrade in more
sophisticated ways with mutt-like regexps.
* It looks like it would be better to do what you are trying to do with
pinning--you want to upgrade certain mozilla packages out of unstable.
You could pin the mozilla packages you want in /etc/apt/preferences.
* You should almost always use the
xargs -i [command] "{}" [options]
format. "{}" becomes your replacement string. This becomes important
if any of the input parameters have spaces in them, or if you need your
replacement string to be something other than the last argument.
* Even better, if you can, is to use xargs -0, which means it expects
null-terminated input strings. This is typically done in conjunction
with find:
find . -name \*.bak -print0 | xargs -0 -i rm "{}"
or even better in this case
find . -name \*.bak -exec rm '{}' ';'
There you go.
--=20
Adam Kessel
http://bostoncoop.net/adam
--4Ckj6UjgE2iN1+kY
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQE/s8HfdTf3ZklQ6qYRAt8yAJ9mhCQJJYJmytwjtkC8T2NiCiFZSgCfbR34
OUgtFgn+6nHXnaAHV9NEmAE=
=YUzn
-----END PGP SIGNATURE-----
--4Ckj6UjgE2iN1+kY--