You are not logged in.
Pages: 1
I tried to create an alias that won't work correctly.
alias depclean="sudo pacman -Rns $(pacman -Qqtd)"The command works fine when I run it from the terminal (it asks pacman about any missing dependencies, and then removes them with a confirmation)
But if I use the alias, the command seems to mess up. I can't pinpoint exactly how though, but I suspect the "$(pacman -Qqtd)" part is confusing the alias somehow.
Right now I tried installing awesomewm then uninstalling it and running the command. In terminal I get this:
$ sudo pacman -Rns $(pacman -Qqtd)
checking dependencies...
:: deluge optionally requires python2-mako: needed for web ui
Packages (7): gobject-introspection-1.40.0-1 python2-beaker-1.6.4-2
python2-mako-0.9.1-2 python2-markupsafe-0.21-1
libxdg-basedir-1.2.0-2 lua-lgi-0.7.2-1 xcb-util-cursor-0.1.1-1
Total Removed Size: 11.45 MiB
:: Do you want to remove these packages? [Y/n] nWith alias:
$ depclean
error: no targets specified (use -h for help)If I were to try to point a finger at what happening, alias does run the "$(pacman -Qqtd)" part, but not correctly or at the very least, not every time the command is written.
Last edited by rabcor (2014-04-27 07:40:42)
Offline
It needs to be a function: you can't do command susbstitution in an alias.
Offline
I see, damn... do you have any idea what I can use instead?
I got this command recommended as something to put in as an alias to begin with :I
Offline
This?
depclean(){ sudo pacman -Rns $(pacman -Qqtd) ;}Offline
what do you mean?
bash: /home/user/.bashrc: line 14: syntax error near unexpected token `('
bash: /home/user/.bashrc: line 14: `alias depclean(){ sudo pacman -Rns $(pacman -Qqtd) ;}'Offline
what do you mean?
bash: /home/user/.bashrc: line 14: syntax error near unexpected token `(' bash: /home/user/.bashrc: line 14: `alias depclean(){ sudo pacman -Rns $(pacman -Qqtd) ;}'
He said function. place the line in you .bashrc file just as is. That creates a function named depclean. If you put alias in front of it, bash tries to make an alias.
Offline
Offline
Have you tried https://wiki.archlinux.org/index.php/Co … _the_shell ? Works for me.
Offline
Have you tried https://wiki.archlinux.org/index.php/Co … _the_shell ? Works for me.
So you need to escape the dollar sign or use single quotes to prevent bash from performing the substitution at the time .bashrc gets loaded.
Offline
You could create a smallscript called depclean with
#!/bin/bash
sudo pacman -Rns $(pacman -Qqtd)Save into a text file called depclean then chmod +x it. You can then add it to your bin directory if you want to put it on your path
Last edited by derekArch (2014-04-28 05:26:58)
Offline
When you use double-quotes in the alias, Bash will expand the subshell $(pacman -Qqtd) to whatever the current output of pacman -Qqtd is when you create the alias. The first time you run the command it will remove those packages. The second time it will try to remove the same packages that you have already removed.
Use single quotes instead to expand the subshell with each invocation (i.e. to create a dynamic command):
alias depclean='sudo pacman -Rns $(pacman -Qqtd)'To see expansion of the alias, type the alias in a (Bash) shell and press ctrl+alt+e. If the names of the packages do not change when you run the command then you have created a static alias.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
Pages: 1