zshaliaszshrccommpacman-package-manager

Why does my command stop working when I put it into an alias?


I am trying to run the following command comm -23 <(pacman -Qqe | sort) <(awk '{print $1}' /desktopfs-pkgs.txt | sort)

I get the following output

autoconf
automake
bison
chromium
code
discord
fakeroot
flex
lib32-mesa-vdpau
lib32-vulkan-intel
lib32-vulkan-radeon
m4
make
mesa-vdpau
nerd-fonts-complete
paru
patch
pkgconf
spotify
terminator
vim
vulkan-intel
vulkan-radeon
xf86-video-amdgpu
xf86-video-ati
xf86-video-intel
xf86-video-nouveau

My goal is to have it output to me the difference between packages I explicitly installed vs what came with Manjaro.

It correctly gives me the output I want and works fine, but when I put it into an alias within my zshrc, it fails.

In my zshrc it looks as follows alias paccom="comm -23 <(pacman -Qqe | sort) <(awk '{print $1}' /desktopfs-pkgs.txt | sort)"

After sourcing, the following is outputted.

~: paccom                                                                                                                                                                                                                   ✔   
acpi
acpid
adobe-source-han-sans-cn-fonts
adobe-source-han-sans-jp-fonts
adobe-source-han-sans-kr-fonts
adobe-source-sans-fonts
alsa-firmware
alsa-utils
amd-ucode
android-tools
android-udev
ark
autoconf
automake
avahi
b43-fwcutter
bison
...

Basically, it seems like the entirety of pacman -Qqe, as if its not actually doing the file comparison correctly.

Any thoughts as to why the behavior changes?


Solution

  • The $1 is substituted by the shell at the time the alias is defined, i.e. awk never sees a $1. You can verify this by displaying your alias with

    alias paccom
    

    You would have to escape the in the alias $ to prevent substitution, or better yet (to save you further headaches) define a function instead of an alias.