You are not logged in.
Hello,guys:
I just wrote a tiny script to remove the packages that were installed as dependencies but are no longer
required by any installed package.However, it always complained to me for some reasons:
my script:
#!/bin/bash
pkg=$(pacman -Qdt|gawk '{ printf "%s ", $1; }')
test -n $pkg
if [ $? = 0 ];then
echo I will remove $pkg
sudo pacman -Rs $pkg
else
echo DO NOT NEED TO REMOVE ANYTHING!
fi
and it complained:
./abs.sh: line 3: test: git: binary operator expected
DO NOT NEED TO REMOVE ANYTHING!
P.S.:
[justin@YZMSQ Desktop]$ pacman -Qdt
git 1.7.0.3-1
phonon 4.4.0-1
What's wrong with my code?I need your help,please.:D
Last edited by YZMSQ (2010-03-30 09:42:47)
This is the way the world ends
Not with a bang but a whimper
-------T·S·Eliot
Offline
Offline
Put the $pkg into "" so it would expand to a string. ( test -n "$pkg" )
At the moment the shell thinks of your line as this: ( pkg="git 1.7.0.3-1 phonon 4.4.0-1" )
test -n git 1.7.0.3-1 phonon 4.4.0-1
( 3 extra arguments: "1.7.0.3-1", "phonon" and "4.4.0-1" )
With the little change above it would be like:
test -n "git 1.7.0.3-1 phonon 4.4.0-1"
Offline
Thank you for your help,I've learned much from your words.
Thanks.:)
This is the way the world ends
Not with a bang but a whimper
-------T·S·Eliot
Offline
Hello
Try this
pacman -Rsn $(pacman -Qdtq)
Thank you for your help.
Well,How could you get "pacman -Rsn"and "pacman -Qdtq"?I just know "-Rs" and "-Qdt"~~~:)
P.S.:I just got them in man,hoho.Thanks.:)
Last edited by YZMSQ (2010-03-30 09:42:10)
This is the way the world ends
Not with a bang but a whimper
-------T·S·Eliot
Offline
As a sidenote, pacman -Rsn $(pacman -Qdtq) should be used with extreme care, because -Qdt can often include packages that you do want to keep.
eg on my box it includes xorg-utils, cmake, cvs, subversion, pyparsing, docutils and more that I use more or less daily.
Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline
Therefore, use zsh and press tab after $(pacman -Qdtq) to expand it, then remove those you want to keep from the line.
Offline